数位的处理

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;
}

嵌套三层循环

posted @ 2019-10-14 07:55  恶魔岛  阅读(264)  评论(0编辑  收藏  举报