Source Code
#include <iostream>
using namespace std;
//B SUM 44+55 = 9
int split(int n){
	int sum =0;
	while(n>0){
		sum+=n%10;
		n/=10;
		//cout<<"sum = "<<sum;
	}
	return sum;
}
int main() {
	int n;
	cin>>n;
	int a[n];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>9){
			 a[i]=split(a[i]);
		//	cout<<a[i]<<endl;
		}
		sum+=a[i];
	}
	if(sum<9) {
		cout<<sum<<endl;
		return 0;
	}
	
	while(sum>9){
		int sum2 = 0;
		while(sum>0){
			sum2+= sum%10;
			sum/= 10;
		}
	//	cout<<sum2<<" ";
		sum = sum2;
	}
	cout<<sum<<endl;
	
	
	return 0;
}
Copy
The Tale of a Generous Prince Razanaws
GNU G++17
3 ms
864 KB
Wrong Answer