Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*During the Coding test, Manoj solved his first problem. The problem he solved has “N” test
- cases. He gets a score for his first problem submission based on the following rules:
- i. If Manoj’s code passes all the “N” test cases, he gets 100 points.
- ii. If Manoj’s code does not pass all the test cases, but passes all the first “M” (M<N) test
- cases, he gets “P” (P<100) points.
- iii. If the conditions 1 and 2 are not satisfied, Manoj does not get any points (i.e. his score
- remains at 0 points).
- You are given a binary array A1, A2... AN of length N, where Ai=1 denotes Manoj's code passed
- the i
- th test case, Ai=0 denotes otherwise. You are also given the two integers M, P. Can you find
- how many points Manoj Scored?
- Input
- First line will contain “T”, number of test cases. Then the test cases follow.
- The first line of each test case contains three space-separated integers N, M, P.
- The second line contains “N” space-separated integer A1, A2... AN
- Output
- For each test case, print Manoj’s Score.*/
- /*Test case 1
- Input
- 2
- 4 2 50
- 1 0 1 1
- 3 2 50
- 1 1 0
- output:
- 0
- 50*/
- #include<stdio.h>
- #include<stdlib.h>
- int main()
- { int test[30],i,test_case,n,m,p;
- int flag = 0,count=0;
- printf("Enter number of test cases: \n");
- scanf("%d",&test_case);
- while(test_case)
- {
- test_case--;
- flag = 0;count=0;
- printf("Enter value of 'N','M' & 'P' according to the question: \n");
- scanf("%d %d %d",&n,&m,&p);
- printf("Enter result of Manoj test cases. If passed press '1' else '0': \n");
- for(i=0;i<n;i++)
- {
- printf("Test No %d: ",i+1);
- scanf("%d",&test[i]);
- if(test[i] == 1)
- count++;
- if(i<m)
- {
- if(test[i] == 1)
- flag++;
- }
- }
- /*Checking whether Manoj has passed all tests*/
- if(count == n)
- {
- printf("\nManoj got total marks = 100");
- goto start;
- }
- /*Checking whether Manoj has passed initial M tests*/
- else if(flag == m)
- {
- printf("\nManoj got total marks = %d:",p);
- goto start;
- }
- else //if both above condition not satisfied then manoj got zero
- {
- printf("\nManoj got total marks = 0 \n");
- goto start;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement