标签(空格分隔): 九度OJ
原题地址:http://ac.jobdu.com/PRoblem.php?pid=1074
程序无任何输入数据
输出具有题目要求的性质的数。如果输出数据不止一组,各组数据之间以回车隔开。
本来打算用字符串的方式做,但是想到上面的那个题目,我已经能够求得一个数的倒序数了,那我直接比较不就行了?所以也就没用转化成字符串的方式。
这个题目表述不清,没有说明白n的最小值范围,试验了之后才知道是0.
另外,跟别人学了一招可以快速翻转数字到字符串:
char str[6];int square= n*n;sprintf(str,"%d",square);这个题的答案:
#include <stdio.h>int main() { int n = 0; while (n < 256) { int temp = n * n; int reverse = 0; while (temp > 0) {//求一个数字的翻转数字 reverse = 10 * reverse + temp % 10; temp /= 10; } if (n * n == reverse) { printf("%d/n", n); } n++; } return 0;}2017 年 3 月 5 日
新闻热点
疑难解答