Advertisement
Mr_kindle

waterlevel.c

Oct 26th, 2022 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.86 KB | None | 0 0
  1. /*. Southwest monsoon arrived in Andhra Pradesh. The Indian Meteorological Department (IMD)
  2. announced that there will be heavy rains in the upcoming “N” days in Vadlamudi area.
  3. Initially, the Vadlamudi area has ‘zero’ millimeters as its water level. The amount of rain on
  4. the i-th day can be described by an integer “Ri” as follows:
  5.  If Ri > 0, the water level of Vadlamudi area increases by Ri millimeters on the i-th day.
  6.  If Ri = 0, there is no rain on the i-th day. The water level decreases by “X” millimeters on
  7. such a day. Though, if the water level is less than X millimeters before the i-th day, then it
  8. becomes zero.
  9. There will be a high alert in Vadlamudi area if the water level becomes greater
  10. than “G” millimetres on at least one of the “N” days. Decide if there will be a High Alert?
  11. Input
  12.  The first line of the input contains a single integer T denoting the number of test cases.
  13.  The first line of each test case contains three space-separated integers N, X and G.
  14.  The second line contains N space-separated integers R1, R2, R3……….RN
  15. Output: For each test case, print - "YES" if there will be a high alert or "NO" otherwise.*/
  16.  
  17. /* INPUT
  18. 3
  19. 4 2 6
  20. 1 3 0 2
  21. 2 1 100
  22. 1 100
  23. 4 2 3
  24. 1 2 0 2
  25. OUTPUT
  26. No
  27. Yes
  28. No*/
  29.  
  30. #include<stdio.h>
  31. #include<stdlib.h>
  32.  
  33. int main()
  34. {   int test_case,n,x,g,i;
  35.     int rain[30],water_level,flag;
  36.     printf("Enter number of test cases:  \n");
  37.     scanf("%d",&test_case);
  38.     while(test_case)
  39.         {
  40.              start: //jump level for goto
  41.            
  42.             if(test_case == 0)
  43.             break;
  44.  
  45.             test_case--;
  46.             water_level = 0;
  47.             flag = 0;
  48.             printf("\nEnter value of 'N','X' & 'G' according to question: ");
  49.             scanf("%d %d %d",&n,&x,&g);
  50.             printf("\nPlease enter amount of rain of all %d days: ",n);
  51.             for(i=0;i<n;i++)
  52.                 {
  53.                     printf("Enter rain amount for day %d: ",i+1);
  54.                     scanf("%d",&rain[i]);
  55.                     if(rain[i]!=0) //if rain amount is non-zero it mean water-level will increse
  56.                         water_level = water_level + rain[i];
  57.                     else
  58.                         {
  59.                             if(x > water_level)//if water-level less than 'X' then it will become zero
  60.                                 water_level = 0;
  61.                             else
  62.                                 water_level = water_level - x;
  63.                         }
  64.                     if(water_level > g)//checking for high alert
  65.                         {
  66.                             printf("\nYES");
  67.                             flag++;
  68.                             break;
  69.                         }
  70.                 }
  71.             if(flag == 0)
  72.             printf("\nNO");
  73.                
  74.  
  75.         }
  76.         return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement