999ms

Untitled

Oct 1st, 2020
930
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data