My main problem is understanding when multiple testcases are taken in a coding problem with the copy feature on sample case, how can I (or should I) get answer for each case after inputting all the cases(t==0)?
I’ve usually skimmed through this concept so please help me understand, following is one such example problem.
The first line contains an integer t
(1≤t≤104
) — the number of test cases.
The first and only line of each test case contains 4
integers a1
, a2
, b1
, b2
(1≤a1,a2,b1,b2≤10
) where a1
and a2
represent the cards Suneet has, and b1
and b2
represent the cards Slavic has, respectively.
test case :
5
3 8 2 6
1 1 1 1
10 10 2 2
1 1 10 10
3 8 7 2
output:
2
0
4
0
2
My solution:
#include <bits/stdc++.h>
using namespace std;
int wins(int a1, int a2, int b1, int b2)
{
int w = 0;
if (a1-b1 > 0 && a2-b2 > 0) w+=2;
if (a1-b2 > 0 && a2-b1 > 0) w+=2;
return w;
}
int main() {
int t , w;
cin>>t;
while(t!=0) {
int a1, a2, b1, b2;
cin>>a1>>a2>>b1>>b2;
w = wins(a1,a2,b1,b2);
cout<<w<<endl;
t--;
}
return 0 ;
}
Shraddha Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.