Source Code
#include <iostream>
using namespace std;

int main() {
	int n, temp, ans = 0, sum = 0;
	cin >> n;
	while (n--) {
		cin >> temp;
		while (temp > 0) {
			sum += temp % 10;
			temp /= 10;
		}
	}
	
	if (sum < 10) {
		cout << sum;
		return 0;
	}
	ans = sum;
	
	while (ans >=10) {
		sum = ans;
		while (sum >= 10) {
			ans = 0;
			ans += sum % 10;
			sum /= 10;
		}
		ans += sum;
	}
	
	cout << ans << endl;
}
Copy
The Tale of a Generous Prince Dana
GNU G++17
17 ms
940 KB
Wrong Answer