hdu 2097 Sky数 寒假集训1 06

来源:互联网 发布:刻录软件找不到文件 编辑:程序博客网 时间:2024/06/07 15:18

原题链接


思路:其实只需求各个位数之和,不需要进行进制转换,开始想的复杂了,同时采用函数进行书写,可大大提高效率和减少代码量


#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int f(int n, int m){int sum = 0;while (n){sum += n % m;n = n / m;}return sum;}int main () {//freopen("E:\input.txt", "r", stdin);int n;while ((cin >> n) && n){if ((f(n, 10) == f(n, 16)) && (f(n, 12) == f(n, 16))){cout << n << " is a Sky Number." << endl;}else{cout << n << " is not a Sky Number." << endl;}}return 0;}


0 0
原创粉丝点击