Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 又被输入坑了，总WA的可以看一下

Posted by lizimeng at 2016-08-18 02:11:22 on Problem 2051
```输入不保证id排序！

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct Query
{
int id;         //id
int period;     //响应周期
int lefttime;   //剩余的时间
};

bool cmp(struct Query a,struct Query b)
{
return a.id < b.id;
}

int main()
{
int i, n, k, t1;
struct Query q[1000];
char input[100];

//读取指令，并计数
n = 0;
gets(input);
while(strcmp(input, "#")!=0)
{
//取出id号
t1 = 0;
for(i=9; input[i]!=' '; i++)
{
t1 *= 10;
t1 += input[i] - '0';
}
q[n].id = t1;

//取出period周期
t1 = 0;
for(i += 1; input[i]!='\0'; i++)
{
t1 *= 10;
t1 += input[i] - '0';
}
q[n].period = t1;
q[n].lefttime = t1;
n++;
gets(input);
}

//读取k
scanf("%d", &k);

//按id排序
sort(q, q+n, cmp);

//响应k次
while(1)
{
//找最小值的下标
t1 = q[0].lefttime;
for(i=1;i<n;i++)
{
if(q[i].lefttime < t1)
t1 = q[i].lefttime;
}

//修改lefttime，并响应
for(i=0;i<n;i++)
{
if(q[i].lefttime==t1)
{
printf("%d\n", q[i].id);
k--;
if(k==0)
return 0;
q[i].lefttime = q[i].period;
}
else
q[i].lefttime -= t1;
}
}

return 0;
}```

Followed by: