解题思路:用一个字符串存储输入的大数,然后按照题目意思进行递归即可
注意事项:这道题做了接近一天,一直改,唉我太菜了。
参考代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
bool yn(char a[]) {
char e[200] = "";
int lena = strlen(a);
if (lena <= 5) {
int s = atoi(a);
if (s % 17 == 0)
return true;
else
return false;
} else {
int b[200] = {0}, c[200] = {0}, d[200] = {0};
int last = 5 * int(a[lena - 1] - '0');
for (int i = 0; i <= lena - 2; i++) {
b[lena - 2 - i] = int(a[i] - '0');
}
if (last <= 9)
c[0] = last;
if (last >= 10) {
c[0] = last % 10;
c[1] = last / 10;
}
int j = 0;
while (j <= lena - 2) { //高精度减法
if (b[j] < c[j]) {
b[j] += 10;
b[j + 1]--;
}
d[j] = b[j] - c[j];
j++;
}
int lend = lena - 2;
while (d[lend] == 0) { //去除多余的0
lend--;
}
int p = 0;
for (int i = lend; i >= 0; i--) {
e[p] = d[i] + '0';
p++;
}
return yn(e);
}
}
int main() {
while (1) {
char a[200] = "";
gets(a);
if (a[0] == '0')
break;
if (yn(a))
cout << 1 << endl;
else
cout << 0 << endl;
}
return 0;
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:531 |
Tom数 (C语言代码)浏览:525 |
陶陶摘苹果2 (C语言代码)浏览:595 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:549 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:1220 |
C二级辅导-等差数列 (C语言代码)浏览:770 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:819 |
Pascal三角 (C++代码)浏览:691 |
WU-程序员的表白 (C++代码)浏览:753 |
Manchester-蛇行矩阵,不需要数组,四个变量,解决问题浏览:5983 |