游客 Signup | Login
中文 | En

3551 - 统计(1)

通过次数

0

提交次数

0

Time Limit : 1 秒 Memory Limit : 128 MB

编程实现从键盘任意输入20个整数,统计非负数个数,并计算非负数之和。

Input

首先输入一个整数K ,表示下面有K行。

接下来的K行,每行输入20个整数。

Output

输出和和个数。以空格分隔。

Examples

Input Format

1
28 49 -31 -11 39 -8 33 26 19 36 -14 -39 -31 -43 25 37 25 -43 -36 -2

Output Format

317 10

Solution C

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main()
{
   // freopen("in","r",stdin);
  //  freopen("out","w",stdout);

      int i, n, sum = 0, counter = 0;
      int m;
      while(scanf("%d",&m)!=EOF){
            while(m--){
                    sum = 0, counter = 0;
       for (i=0; i < 20; i++)
	   {
		scanf("%d", &n);
        if (n >= 0)
        {
			sum += n;
           	counter++;
        }
      }
       printf("%d %d\n", sum,counter);
      }
    }
  return 0;
}

Solution C++

#include<cstdio>
#include<cstdlib>
using namespace std;
int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		int sum[100] = { 0 };
		int count[100] = { 0 };
		for (int i = 0; i < n; i++)
		{
			int num;
			for (int j = 0; j < 20; j++)
			{
				scanf("%d", &num);
				if (num >= 0)
				{
					count[i]++;
					sum[i] += num;
				}
			}
			printf("%d %d\n", sum[i], count[i]);
		}
	}
}