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 &z){
     long long x=0;
    while(z>0){
        x+=z%10;
        z/=10;
    }
    return x;
}
int main()
{
     long long n,sm=0;
     cin>>n;
     for(int i=0;i<n;i++){
        long long 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
81 ms
944 KB
Wrong Answer