Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*A schedule of a restaurant waiter for 30 days is provided. The waiter gets Rs. “S” for every
- day he/she worked. As working continuously for the most happening restaurant is a hectic job,
- so the restaurant owner introduced a beneficiary policy to give a bonus to its waiters.
- According to that policy, the company will check the longest streak for which a waiter has
- worked and will reward Rs. “R” for every day of that streak as a bonus pay. Calculate the
- waiter monthly salary (including the bonus pay).
- Note:
- A binary string of length 30, where '0' denotes waiter was on leave and '1' denotes working.
- If there are two or more longest streaks of same length, only one is counted for the bonus pay.
- Input Format
- The first line contains an integer T denoting the number of test cases.
- The first line of each test case contains S and R.
- Second line contains a binary string of length 30, where '0' denotes that waiter was on leave
- and '1' denotes working.
- Output Format
- For each test case, output – the salary received by waiter (including the bonus pay).*/
- /*aLSO available on Pastebin.com*/
- /*INPUT
- 3
- 6 3
- 111100110101100000101100011111
- 8 2
- 111010111101001010100100111101
- 5 6
- 011101010100101000001101000010
- OUTPUT
- 117
- 152
- 78*/
- #include<stdio.h>
- #include<stdlib.h>
- int main()
- { int test_case,s,r,i,total_salary;
- int day[35],present,streak,max;
- printf("Enter number of test cases: \n");
- scanf("%d",&test_case);
- while(test_case)
- {
- test_case--;
- present = 0;
- streak = 0;
- max = 0;
- printf("\nPlease enter value of 'S' & 'R' according to question: ");
- scanf("%d %d",&s,&r);
- printf("\nPlease enter the binary streak (for 'Present' press '1' else '0'): \n");
- for(i=0;i<30;i++)
- {
- printf("day %d: ",i+1);
- scanf("%d",&day[i]);
- if(day[i] == 1)
- {
- present++; //counting present days
- streak++; //counting streak
- }
- else //for absent days
- {
- if(streak > 0) //checking if first day is absent day then do nothing
- {
- if(streak > max)
- max = streak;
- streak = 0;
- }
- }
- if(streak> max)//in order to find the longest string
- max = streak;
- }
- }
- total_salary = present * s + max * r;
- printf("\n\ntotal salary = %d",total_salary);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement