5 条题解
-
1赵青海 (huhe) LV 7 SU @ 2022-5-8 21:08:11
/***************************************** 备注: ******************************************/ #include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; int main() { string a; cin >> a; int len = a.size(); while(len > 1) { int sum =0; for(int i = 0 ; i < len ; i++) sum += a[i] - 48; a = to_string(sum); len = a.size(); } cout << a << endl; return 0; }
-
12022-2-26 11:25:03@
#include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; char a[N]; int main() { cin >> a; int len = strlen(a); int sum = 0; for (int i = 0 ; i < len; i++) { sum += (a[i] - '0'); } while(sum >= 10) { int ans = 0; while(sum != 0) { ans += sum%10; sum /= 10; } sum = ans; } cout << sum << endl; }
-
02022-2-26 11:22:57@
#include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; char a[N]; int main() { cin >> a; int len = strlen(a); int sum = 0; for (int i = 0 ; i < len; i++) { sum += (a[i] - '0'); } while(sum >= 10) { int ans = 0; while(sum != 0) { ans += sum%10; sum /= 10; } sum = ans; } cout << sum << endl; }
-
02022-2-26 11:21:04@
#include <string.h> #define M 1000000 int main(void) { long long a, b; char s[M+1]; int i; while (scanf("%s", s) != EOF) { if (strcmp(s, "0") == 0) break; a = 0; for (i=0; s[i]; i++) a += s[i]-'0'; while (a>=10) { b = 0; while (a) { b += a%10; a /= 10; } a = b; } printf("%lld\n", a); } return 0; }```
-
-12021-10-23 19:10:25@
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main() { int n; cin >> n; int sum = 0; while(1) { if(n == 0) { if(sum >= 10) { n = sum; sum = 0; } else { cout << sum; break; } } else { sum += n%10; n = n/10; } } }
- 1
信息
- ID
- 1134
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 3
- 标签
- 递交数
- 135
- 已通过
- 73
- 上传者