2316 - 多多洛的礼物
Input
首先有一个数字T,代表有T组数据;每组数据有一个数字n,接下来有n行,每行包括两个数字s和t,s表示小朋友们的性别(0是女生,1是男生),t表示该小朋友将会送给多多洛多少颗糖果或巧克力。(0<=s<=1, 1<=t<=10)
Output
对于每组数据输出两个数字,分别表示多多洛会收到的巧克力和糖果的总数,两个数字之间用一个空格隔开(第二个数字后面没有空格,不要多加)。
Examples
Input
2 1 0 1 3 0 5 1 6 0 3
Output
1 0 8 6
Solution C++
#include <cstdio> #include <iostream> using namespace std; int main() { int T; cin >> T; while(T--) { int n, s, a, g = 0, b = 0; cin >> n; for(int i = 0; i < n; i++) { cin >> s >> a; if(s == 0) g += a; else b += a; } cout << g << " " << b << endl; } return 0; }
