C++ 判断自幂数算法实现
#include
bool isSelfNum(int num) { int sum = 0; int temp = num; int digit = 0; while (temp > 0) { temp /= 10; digit++; } temp = num; while (temp > 0) { int remainder = temp % 10; sum += pow(remainder, digit); temp /= 10; } return sum == num; }
int main() { int M; cin >> M; for (int i = 0; i < M; i++) { int num; cin >> num; if (isSelfNum(num)) { cout << 'T' << endl; } else { cout << 'F' << endl; } } return 0; }
原文地址: https://www.cveoy.top/t/topic/qoK6 著作权归作者所有。请勿转载和采集!