杭电------2097 Sky数(C语言写)
//这个题没有一次过,哈哈哈哈,题意理解错了,开始还以为是必须加起来等于22呢 //其实就是依次算出个进制下的和,虽然每个循环最多循环四次,但是还是加上必要的判断,想办法让 //提前结束 #include<stdio.h> int main() { int n, x; int sum, sum1, sum2; while (scanf("%d", &n) != EOF&&n != 0) { x = n; sum = 0;//16进制 sum1 = 0;//12进制 sum2 = 0;//10进制 while (x != 0) { sum += x % 16; x = x / 16; } x = n; while (x != 0) { sum1 += x % 12; x = x / 12; if (sum1 > sum) {//如果四个数还没循环玩,已经大于了,不必继续下去 break; } } if (sum == sum1) {//判断十六进制个十二进制下是否相等,不相等就直接结束了 x = n; while (x != 0) { sum2 += x % 10; x = x / 10; if (sum2 > sum) { break; } } if (sum2 == sum) { printf("%d is a Sky Number.\n", n); } else { printf("%d is not a Sky Number.\n", n); } } else { printf("%d is not a Sky Number.\n", n); } } return 0; }