Problem H. Math Game
Input file: standard input
Output file: standard output
Time limit: 1 seconds
Memory limit: 128 megabytes
大家都知道馬大佬很皮
馬大佬很喜歡研究數字的數位和,現在馬大佬手里有 n 個數字,他想知道這 n 個數字里 面有多少個數字的數位和是 7 的倍數?
Input
輸入第一行一個整數 T,代表接下來有 T 組測驗資料 對于每一組測驗資料,先輸入一個整數 n 代表 n 個數字 接下來一行輸入 n 個數 a[i],代表每一個數字
1 <= T <= 10,1 <= n <= 2*105 ,1 <= a[i] <= 10^9
Output
對于每一組測驗資料,輸出對應答案,
Example
|
standard input |
standard output |
|
1 5 16 2 7 14 95 |
3 |
#include<iostream> #include<cstring> #define N 200000 using namespace std; int main() { int t,a[N]; memset(a,0,sizeof(a)); cin >> t;//樣例個數 while(t--) { int n,sum = 0; cin >> n;//單個樣例的個數 for(int i = 1;i <= n;i++) { int x; cin >> x; int ans = 0; while(x)//對剛讀入的數立刻進行處理 { ans += x % 10; x = x / 10; } if(ans % 7 == 0) sum++; } cout << sum << endl; } return 0; }
嵌套三層回圈
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/96299.html
標籤:C++
上一篇:CodeForces 1228F - One Node is Gone
下一篇:BF演算法(蠻力匹配)
