poj 1047 Round and Round We Go
来源:互联网 发布:vue.js可以做什么 编辑:程序博客网 时间:2024/05/01 21:14
//大数相乘!注意最后一位是否有进位! #include <iostream>#include <cstdio>#include <string>#include <algorithm>using namespace std;int ans[100];int main(){ string str; int input[70], tmp[70]; int i, j, k, len; bool flag1; while (cin >> str) { len = str.length(); flag1 = false; for (i = len-1, j = 0; i >= 0; i--, j++) { input[j] = str[i] - 48; tmp[j] = input[j]; } sort(tmp, tmp+j); for (i = 1; i <= len; i++) { if (flag1) break; memset(ans, 0, sizeof(ans)); for (j = 0; j < len; j++) { ans[j] += input[j]*i; if (ans[j] >= 10) { ans[j+1] += ans[j]/10; ans[j] %= 10; } } if (ans[j] >= 10) { ans[j+1] += ans[j]/10; ans[j] %= 10; j++; } sort(ans, ans+j); for (k = 0; k < j; k++) { if (tmp[k] != ans[k]) { flag1 = true; break; } } if (flag1) break; } if (flag1) cout << str << " is not cyclic" << endl; else cout << str << " is cyclic" << endl; } system("pause");}