1.已知组数
A+B for Input-Output Practice (VIII)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 135986 Accepted Submission(s): 41510
Problem Description
你的任务是求许多数的和。
Input
第一行需要输入一个整数N,接下来会有N行。 每一行开始输入一个整数M,然后会有M个数在同一行。
Output
对于每组输入,要求在一行输出它们的和。并且你要保证每组输出之间有一空行。
Sample Input
3 4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
Sample Output
10
15
6
Author
icy
source:HDU - 1096
参考代码如下:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m,a[101],b;
scanf("%d",&n);
b=n;
int f=0;
while(b--)
{
if(f==1) printf("\n");
scanf("%d",&m);
int i,s=0;
for(i=1; i<=m; i++)
{
scanf("%d",&a[i]);
s=s+a[i];
}
printf("%d\n",s);
f=1;
}
return 0;
}
输出如下:
2.多组输入
Secret Number
*Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5679 Accepted Submission(s): 2437*
Problem Description
有一天, KIKI 收到一张奇怪的信, 信上要KIKI 计算出给定数各个位上数字为偶数的和.
eg. 5548,结果为12 , 等于 4 + 8。
KIKI 很苦恼. 想请你帮忙解决这个问题.
Input
输入数据有多组,每组占一行,只有一个数字,保证数字在INT范围内.
Output
对于每组输入数据,输出一行,每两组数据之间有一个空行.
Sample Input
415326
3262
Sample Output
12
10
Author
kiki
source:HDU-2113
参考代码如下
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n;
int a[10001];
int f=0;
while(~scanf("%d",&n))
{
if(f==1)printf("\n");
int i;
int j=0,sum=0;
while(n)
{
a[++j]=n%10;
n=n/10;
}
for(i=1;i<=j;i++)
if(a[i]%2==0) sum+=a[i];
printf("%d\n",sum);
f=1;
}
return 0;
}
输出如下