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

请问为什么我总过不去呢?我自己写了几组测试数据也都对啊!

Posted by clj511878301 at 2008-11-17 14:51:11 on Problem 2051 and last updated at 2008-11-17 14:51:46
#include <iostream>

using namespace std;

struct User{
        int id;
        int period;
        int time;
        };
User user[1000];
int cmp(const void *e1,const void *e2)
{
        if(((User*)e1)->time<((User*)e2)->time)     return -1;
        else if(((User*)e1)->time>((User*)e2)->time)        return 1;
        else if(((User*)e1)->id<((User*)e2)->id)    return -1;
                else return 1;
}
int main()
{
        char r[10];
        int i=0,k,time;
        while(scanf("%s",r)&&r[0]!='#')
        {
                scanf("%d %d",&user[i].id,&user[i].period);
                user[i].time=user[i].period;
                i++;
        }
        scanf("%d",&k);
        int n=i;
        qsort(user,n,sizeof(User),cmp);
        time=user[0].time;
        while(k)
        {
                for(i=0;i<n;i++)
                        if(time%user[i].time==0)
                                {
                                        printf("%d\n",user[i].id),k--;
                                        if(k==0)        break;
                                }
                time++;
        }
        return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator