Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string get_cnt(string& s) {
- int cur = 0;
- for (char ch : s) {
- cur += ch - '0';
- }
- return to_string(cur);
- }
- int main() {
- string x;
- cin >> x;
- while (x.size() > 1u) {
- x = get_cnt(x);
- }
- cout << x << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement