Advertisement
Mr_kindle

manojmarks.c

Oct 26th, 2022 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.72 KB | Source Code | 0 0
  1. /*During the Coding test, Manoj solved his first problem. The problem he solved has “N” test
  2. cases. He gets a score for his first problem submission based on the following rules:
  3. i. If Manoj’s code passes all the “N” test cases, he gets 100 points.
  4. ii. If Manoj’s code does not pass all the test cases, but passes all the first “M” (M<N) test
  5. cases, he gets “P” (P<100) points.
  6. iii. If the conditions 1 and 2 are not satisfied, Manoj does not get any points (i.e. his score
  7. remains at 0 points).
  8. You are given a binary array A1, A2... AN of length N, where Ai=1 denotes Manoj's code passed
  9. the i
  10. th test case, Ai=0 denotes otherwise. You are also given the two integers M, P. Can you find
  11. how many points Manoj Scored?
  12. Input
  13.  First line will contain “T”, number of test cases. Then the test cases follow.
  14.  The first line of each test case contains three space-separated integers N, M, P.
  15.  The second line contains “N” space-separated integer A1, A2... AN
  16. Output
  17. For each test case, print Manoj’s Score.*/
  18. /*Test case 1
  19. Input
  20. 2
  21. 4 2 50
  22. 1 0 1 1
  23. 3 2 50
  24. 1 1 0
  25. output:
  26. 0
  27. 50*/
  28.  
  29. #include<stdio.h>
  30. #include<stdlib.h>
  31.  
  32. int main()
  33. {   int test[30],i,test_case,n,m,p;
  34.     int flag = 0,count=0;
  35.     printf("Enter number of test cases:  \n");
  36.     scanf("%d",&test_case);
  37.     while(test_case)
  38.         {
  39.            
  40.  
  41.             test_case--;
  42.             flag = 0;count=0;
  43.             printf("Enter value of 'N','M' & 'P' according to the question: \n");
  44.             scanf("%d %d %d",&n,&m,&p);
  45.             printf("Enter result of Manoj test cases. If passed press '1' else '0': \n");
  46.             for(i=0;i<n;i++)
  47.                 {
  48.                     printf("Test No %d:  ",i+1);
  49.                     scanf("%d",&test[i]);
  50.                     if(test[i] == 1)
  51.                         count++;
  52.                     if(i<m)
  53.                         {
  54.                             if(test[i] == 1)
  55.                                 flag++;
  56.                         }
  57.                 }
  58.             /*Checking whether Manoj has passed all tests*/
  59.             if(count == n)
  60.                 {
  61.                     printf("\nManoj got total marks = 100");
  62.                     goto start;
  63.                 }
  64.             /*Checking whether Manoj has passed initial M tests*/
  65.             else if(flag == m)
  66.                 {
  67.                     printf("\nManoj got total marks = %d:",p);
  68.                     goto start;
  69.                 }
  70.             else //if both above condition not satisfied then manoj got zero
  71.                 {
  72.                     printf("\nManoj got total marks = 0 \n");
  73.                     goto start;
  74.                 }
  75.            
  76.            
  77.         }
  78.         return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement