Source Code
#include <iostream>
#include <string>
using namespace std;

int main() {
	int n;
	cin >> n;

	long long int count = 0;

	for (int i = 0; i < n; i++)
	{
		string num; 
		cin >> num;

		for (int j = 0; j < num.length(); j++)
		{
			int n = (int)num[j] - '0';
			count += n;
		}
	}


	while (count > 9) {
		long long int sum = 0;
		while (count != 0)
		{
			sum += count % 10;
			count /= 10;
		}
		count = sum;
	}

	cout << count;

	return 0;
}
Copy
The Tale of a Generous Prince Qusay
GNU G++17
52 ms
952 KB
Accepted