-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathcan_cons.cpp
More file actions
45 lines (42 loc) · 792 Bytes
/
can_cons.cpp
File metadata and controls
45 lines (42 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
int digSum(int n)
{
int ans = 0;
while(n != 0)
{
ans += n%10;
n/= 10;
}
return ans;
}
string canConstruct(vector <int> a)
{
// Return "Yes" or "No" denoting whether you can construct the required number.
long long int sum = 0;
for(int i = 0; i < a.size(); i++)
{
sum += digSum(a[i]);
}
if(sum % 3 == 0)
{
return "Yes";
}
else
return "No";
}
int main() {
int t;
cin >> t;
for(int a0 = 0; a0 < t; a0++){
int n;
cin >> n;
vector<int> a(n);
for(int a_i = 0; a_i < n; a_i++){
cin >> a[a_i];
}
string result = canConstruct(a);
cout << result << endl;
}
return 0;
}