Source Code
#include <iostream>
using namespace std;
int main()
{
	long long n, a[100000], sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int x = 0;
		while (a[i] >= 0) {
			x += a[i] % 10;
			a[i] /= 10;
		}
		a[i] = x;
	}
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	while (sum /10 > 0)
	{
		ans = 0;
		while (ans >= 0) {

			ans += sum % 10;
			ans /= 10;
		}
		sum = ans;
	}
	cout << sum;
}
Copy
The Tale of a Generous Prince microwave6
GNU G++17
2057 ms
320 KB
Time Limit Exceeded