Advertisement
999ms

Untitled

Oct 1st, 2020
1,346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. string get_cnt(string& s) {
  6.     int cur = 0;
  7.     for (char ch : s) {
  8.         cur += ch - '0';
  9.     }
  10.     return to_string(cur);
  11. }
  12.  
  13. int main() {
  14.     string x;
  15.     cin >> x;
  16.     while (x.size() > 1u) {
  17.         x = get_cnt(x);
  18.     }
  19.     cout << x << '\n';
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement