CF231A - Team
題目來源:http://codeforces.com/problemset/problem/231/A
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output
Print a single integer — the number of problems the friends will implement on the contest.
Examples
input
3
1 1 0
1 1 1
1 0 0
output
2
input
2
1 0 0
0 1 1
output
1
Note
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
題目大意:
三個朋友組隊打程式設計比賽,當有兩個以上的人有把握解決問題的時候,就認為可以解決這題。第一行輸入問題數量n, 接下來的每一行,都有三個數字,表示三個人是否有把握解決問題,有把握用1,沒把握用0。問最後有把握做多少題。
題目分析:
顯然,只需要將每一行的三個數加起來,用sum存起來,如果sum>2說明有把握解決,標記數量加1。
參考程式碼:
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, a, b, c, ans = 0;
cin >> n;
for(int i=1; i<=n; i++){
cin >> a >> b >> c;
a += b + c;
if(a>=2)
ans ++;
}
cout << ans;
return 0;
}