Time Limit: 1000ms
Memory Limit: 128000KB
64-bit integer IO format: Java class name:
Submit Status
key天生對數字特别敏感,一次偶然的機會,他發現了一個有趣的四位數2992,這個數,它的十進制數表示,其四位數字之和為2+9+9+2=22,它的十六進制數BB0,其四位數字之和也為22,同時它的十二進制數表示1894,其四位數字之和也為22。key非常喜歡這種四位數(三種進制的和相等),由于他的發現,是以這裡我們命名其為key數。但是要判斷這樣的數還是有點麻煩啊,那麼現在請你幫忙來判斷任何一個十進制的四位數,是不是key數吧。
Input
輸入含有一些四位正整數,如果為0,則輸入結束。
Output
若n為Sky數,則輸出“#n is a sky Number.”,否則輸出“#n is not a sky Number.”。每個結果占一行。注意:#n表示所讀入的n值。
Sample Input
2992
1234
0
Sample Output
2992 is a Sky Number.
1234 is not a Sky Number.
代碼:
1 #include <stdio.h>
2 #include <string.h>
3 #include <math.h>
4 #include <limits.h>
5 #include <algorithm>
6 #include <iostream>
7 #include <ctype.h>
8 #include <iomanip>
9 #include <queue>
10 #include <map>
11 #include <stdlib.h>
12
13 using namespace std;
14
15 int sum_k(int n,int k)
16 {
17 int s=0;
18 while(n!=0)
19 {
20 s+=n%k;
21 n/=k;
22 }
23 return s;
24 }
25 int main()
26 {
27 int n;
28 while(~scanf("%d",&n)){
29 if(n==0)
30 break;
31 int a,b,c;
32 a=sum_k(n,10);
33 b=sum_k(n,12);
34 c=sum_k(n,16);
35 if(a==b&&a==c)
36 printf("%d is a Sky Number.\n",n);
37 else
38 printf("%d is not a Sky Number.\n",n);
39 }
40 }