An Introduction To Programming Through C++
IIT Bombay.
Week 7- Programming Assignment 3:
Each morning, a bureacrat receives letters, each letter has an identifying number, and denotes a job that takes one hour's work. The bureaucrat places the letters in an "In-tray", one above the other, with the letters received earlier below those received later. Each day the bureaucrat works for at most 8 hours. In each hour, he picks up the letter if any from the top of In-tray, does the job and throws away the letter. If the jobs finish early, the bureaucrat goes home early; if the jobs do not finish in the 8 hours, the letters remain in the In-tray. The next day, the arriving letters are put on top of the In-tray, as usual.
Write a program to model this process. Its input should be in the following form. First there is a number n, denoting the number of days to be modelled. Following that there are n sequences of numbers, the ith sequence describing the letters arriving on the ith day. Each
sequence starts of with a number giving the number of letters in the sequence, following which are the ids of the letters (in arrival order).Your program is to print the ids of the letters left
unprocessed at the end of the n days, if any, from the bottom of the In-tray to the top.You should assume that the In-tray will never have more than 20 letters.
Input instance (it is OK if the letter ids repeat)
2
10 1 2 3 4 5 6 7 8 9 10
9 11 2 3 4 5 6 7 8 9
Output
1
2
11
Sample Test Cases
Input Output
Test Case 1
2
10 1 2 3 4 5 6 7 8 9 10
9 11 2 3 4 5 6 7 8 9
1
2
11
Input Output
Test Case 1
2
10 1 2 3 4 5 6 7 8 9 10
9 11 2 3 4 5 6 7 8 9
1
2
11
WRITE/COPY THESE CODE DIRECTLY IN NPTEL TERMINAL AND COMPILE AND RUN THEN SUBMIT.
PROGRAM:#include <iostream>
using namespace std;
int main(){
int intray[20], top=0;
int n; cin >> n;
for(int i=0; i<n; i++){
int nToday; cin >> nToday;
for(int j=0; j<nToday; j++){
int letter; cin >> letter;
intray[top] = letter;
top++;
}
top = max(top-8,0);
}
for(int i=0; i<top; i++)
cout << intray[i]<<endl;
}
CLICK ON BELOW LINK.
<<CLICK HERE FOR WEEK 7:PROGRAMMING -01>>
<<CLICK HERE FOR WEEK 7: PROGRAMMING-02>> FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
No comments:
Post a Comment
If you have any problems related to solutions or any concept please let me know.