Description
In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code any time. Here you need to write a contest print server to handle all the requests.
Input
In the first line there is an integer T(T<=10),which indicates the number of test cases.
In each case,the first line contains 5 integers n,s,x,y,mod (1<=n<=100, 1<=s,x,y,mod<=10007), and n lines of requests follow. The request is like "Team_Name request p pages" (p is integer, 0<p<=10007, the length of "Team_Name" is no longer than 20), means the team "Team_Name" need p pages to print, but for some un-know reason the printer will break down when the printed pages counter reached s(s is generated by the function s=(s*x+y)%mod ) and then the counter will become 0. In the same time the last request will be reprint from the very begin if it isn't complete yet(The data guaranteed that every request will be completed in some time).
You can get more from the sample.
Output
Every time a request is completed or the printer is break down,you should output one line like "p pages for Team_Name",p is the number of pages you give the team "Team_Name".
Please note that you should print an empty line after each case.
Sample Input
Sample Output
题意:输入五个数,n,s,x,y,mod,接下i来有n行,表示每个队需要打印的纸张数,若打印的纸张数总和等于s,则s就变成(s*x+y)%mod ),若打印的总张数超过s,把小于等于s的那部分打印出来,然后s变成(s*x+y)%mod )。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,s,x,y,Mod;
struct node
{
char name[30];
int page;
}Node[105];
void print()
{
int t=0,sum=0;
while(t<n)
{
if(sum==s)
{
cout<<"0"<<" pages for "<<Node[t].name<<endl;
s=(s*x+y)%Mod;
sum=0;
}
else if(sum+Node[t].page<=s)
{
cout<<Node[t].page<<" pages for "<<Node[t].name<<endl;
sum+=Node[t].page;
t++;
}
else
{
cout<<s-sum<<" pages for "<<Node[t].name<<endl;
sum=0;
s=(s*x+y)%Mod;
}
}
}
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
scanf("%d %d %d %d %d",&n,&s,&x,&y,&Mod);
for(int j=0;j<n;j++)
{
scanf("%s request %d pages",&Node[j].name,&Node[j].page);
}
print();
cout<<endl;
}
return 0;
}