Jishan's Log 5: Codeforces 231A solution
Codeforces 231A: Team
What the problem wants?
The 3 friends have formed a team and while solving problems, they want to make sure how many are confident about the solution. If 2/3 are confident, then they will implement the solution. Else they will ignore it.
How to solve the problem?
Algorithm:
For variable names, look at the code below:
1) take n tests as input
2) from i = 1 => 3 ( 0 => 2)
take an input, and see if it is 1. If it is, then increment the i_counter. Keep checking this for the remaining two. Lastly, check if the i_counter has values >= 2. If yes, increment the sol_counter and finally print it.
The Code:
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
fastio;
int n; scanf("%d", &n);
int sol_count = 0;
while (n--)
{
int i_count = 0;
for(int i=0; i<3; i++)
{
int x; scanf("%d", &x);
if(x == 1) {i_count++;}
}
if(i_count >= 2) {sol_count++;}
}
printf("%d\n", sol_count);
}
Comments
Post a Comment