Problem description
source: https://uva.onlinejudge.org/external/128/12895.html
Input
The first line of input is an integer, T that determines the number of test cases. Each of the next T lines contain a positive integer N, where N ≤ 1000000000.
Output
For each line of input, there will be one line of output. If N is an Armstrong number print ‘Armstrong’, otherwise print ‘Not Armstrong’ (without the quotes).
Sample Input
3
153
2732
54748
Sample Output
Armstrong
Not Armstrong
Armstrong
Solution:
source: https://uva.onlinejudge.org/external/128/12895.html
Input
The first line of input is an integer, T that determines the number of test cases. Each of the next T lines contain a positive integer N, where N ≤ 1000000000.
Output
For each line of input, there will be one line of output. If N is an Armstrong number print ‘Armstrong’, otherwise print ‘Not Armstrong’ (without the quotes).
Sample Input
3
153
2732
54748
Sample Output
Armstrong
Not Armstrong
Armstrong
Solution:
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include<stdio.h> #include<stdlib.h> #include<math.h> using namespace std; int main() { int i, t, n, ArmN, ArmNumbuer, digit; while(scanf("%d",&t)==1) { for(i=0; i<t; i++) { scanf("%d", &ArmN); ArmNumbuer = ArmN; n = 0; while(ArmN > 0) { ArmN /= 10; n+=1; } ArmN = ArmNumbuer; while(ArmN > 0) { digit = ArmN % 10; ArmN /= 10; ArmNumbuer -= pow(digit, n); } if(ArmNumbuer == 0) printf("Armstrong\n"); else printf("Not Armstrong\n"); } } return 0; }
No comments:
Post a Comment
Write your comment - Share Knowledge and Experience