编程基础之循环基础

描述

2008年北京奥运会,A国的运动员参与了n天的决赛项目(1≤n≤17)。现在要统计一下A国所获得的金、银、铜牌数目及总奖牌数。

输入输入n+1行,第1行是A国参与决赛项目的天数n,其后n行,每一行是该国某一天获得的金、银、铜牌数目,以一个空格分开。输出输出1行,包括4个整数,为A国所获得的金、银、铜牌总数及总奖牌数,以一个空格分开。样例输入

3
1 0 3
3 1 0
0 3 0

样例输出

4 4 3 11
 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     int a,x,y,z,jin=0,yin=0,ton=0,b;
 7     //double x;
 8     cin>>a;
 9     for(int i=0;i<a;i++)
10     {
11         cin>>x>>y>>z;
12     jin+=x;
13     yin+=y;
14     ton+=z;}
15     b=jin+yin+ton;    
16     printf("%d %d %d %d",jin,yin,ton,b);    
17     return 0;
18 }

 

posted @ 2016-05-11 17:12  a_Autumn_moon  阅读(354)  评论(0编辑  收藏  举报