Source Code
#include <bits/stdc++.h>

using namespace std;
int ans=0;
/*int f( long long z, long long sum){
    if(z==0){
        return sum;
    }
    f(z/10,sum+=z%10);
}*/
int f( long long unsigned&z){
     long long unsigned x=0;
    while(z>0){
        x+=z%10;
        z/=10;
    }
    return x;
}
int main()
{
     long long unsigned n,sm=0;
     cin>>n;
     for(int i=0;i<n;i++){
        long long unsigned c;
        cin>>c;
        while(c>10){
            c=f(c);
        }
        sm+=c;
     }
     while(sm>10){
        sm=f(sm);
     }
     cout<<sm;

   return 0;
}
Copy
The Tale of a Generous Prince fakher20
GNU G++17
71 ms
956 KB
Wrong Answer