Advertisement
Mr_kindle

waitersalary.c

Oct 26th, 2022 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. /*A schedule of a restaurant waiter for 30 days is provided. The waiter gets Rs. “S” for every
  2. day he/she worked. As working continuously for the most happening restaurant is a hectic job,
  3. so the restaurant owner introduced a beneficiary policy to give a bonus to its waiters.
  4. According to that policy, the company will check the longest streak for which a waiter has
  5. worked and will reward Rs. “R” for every day of that streak as a bonus pay. Calculate the
  6. waiter monthly salary (including the bonus pay).
  7. Note:
  8.  A binary string of length 30, where '0' denotes waiter was on leave and '1' denotes working.
  9.  If there are two or more longest streaks of same length, only one is counted for the bonus pay.
  10. Input Format
  11.  The first line contains an integer T denoting the number of test cases.
  12.  The first line of each test case contains S and R.
  13.  Second line contains a binary string of length 30, where '0' denotes that waiter was on leave
  14. and '1' denotes working.
  15. Output Format
  16.  For each test case, output – the salary received by waiter (including the bonus pay).*/
  17.  
  18. /*aLSO available on Pastebin.com*/
  19.  
  20. /*INPUT
  21. 3
  22. 6 3
  23. 111100110101100000101100011111
  24. 8 2
  25. 111010111101001010100100111101
  26. 5 6
  27. 011101010100101000001101000010
  28. OUTPUT
  29. 117
  30. 152
  31. 78*/
  32.  
  33.  
  34. #include<stdio.h>
  35. #include<stdlib.h>
  36.  
  37. int main()
  38. {   int test_case,s,r,i,total_salary;
  39.     int day[35],present,streak,max;
  40.     printf("Enter number of test cases:  \n");
  41.     scanf("%d",&test_case);
  42.     while(test_case)
  43.         {
  44.            
  45.             test_case--;
  46.             present = 0;
  47.             streak = 0;
  48.             max = 0;
  49.             printf("\nPlease enter value of 'S' & 'R' according to question: ");
  50.             scanf("%d %d",&s,&r);
  51.             printf("\nPlease enter the binary streak (for 'Present' press '1' else '0'): \n");
  52.             for(i=0;i<30;i++)
  53.                 {
  54.                     printf("day %d: ",i+1);
  55.                     scanf("%d",&day[i]);
  56.                     if(day[i] == 1)
  57.                         {
  58.                             present++; //counting present days
  59.                             streak++;  //counting streak
  60.                         }
  61.                     else //for absent days
  62.                         {
  63.                             if(streak > 0) //checking if first day is absent day then do nothing
  64.                                 {
  65.                                     if(streak > max)
  66.                                          max = streak;
  67.                                     streak = 0;
  68.                                 }
  69.                         }
  70.                         if(streak> max)//in order to find the longest string
  71.                             max = streak;
  72.                        
  73.                        
  74.                 }
  75.         }
  76.         total_salary = present * s + max * r;
  77.        
  78.         printf("\n\ntotal salary = %d",total_salary);
  79.         return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement