HDU1084
#include<iostream> #include<algorithm> #include<queue> using namespace std; struct stu { int pro; int pos; int score; int tra_time; }; bool less_time( stu & m1, stu & m2) { return m1.tra_time < m2.tra_time; } bool less_pos( stu & m1, stu & m2) { return m1.pos < m2.pos; } queue<stu> score_get(queue<stu> &qq,int score) { int n=qq.size(); if(n==0) return qq; if(n==1) { qq.front().score=score+5; return qq; } stu *a=new stu[n]; int i=0; while(!qq.empty()) { a[i]=qq.front(); qq.pop(); ++i; } sort(a,a+n,less_time); int mid=n/2; for(int i=0;i<n;++i) { if(i<mid) a[i].score=score+5; else a[i].score=score; qq.push(a[i]); } return qq; delete []a; } int main() { int n=0; while(cin >> n) { if(n<0) break; stu *a=new stu[n]; stu *b=new stu[n]; int hour=0,min=0,sec=0; queue<stu> q4,q3,q2,q1; int j=0; for(int i=0;i<n;++i) { scanf("%d%d:%d:%d",&a[i].pro,&hour,&min,&sec); a[i].tra_time=hour*3600+min*60+sec; a[i].pos=i; switch(a[i].pro) { case 5: { a[i].score=100; b[j++]=a[i]; break; } case 4: { q4.push(a[i]); break; } case 3: { q3.push(a[i]); break; } case 2: { q2.push(a[i]); break; } case 1: { q1.push(a[i]); break; } case 0: { a[i].score=50; b[j++]=a[i]; break; } } } queue<stu> q11=score_get(q1,60); while(!q11.empty()) { b[j++]=q11.front(); q11.pop(); } queue<stu> q22=score_get(q2,70); while(!q22.empty()) { b[j++]=q22.front(); q22.pop(); } queue<stu> q33=score_get(q3,80); while(!q33.empty()) { b[j++]=q33.front(); q33.pop(); } queue<stu> q44=score_get(q4,90); while(!q44.empty()) { b[j++]=q44.front(); q44.pop(); } sort(b,b+n,less_pos); for(int i=0;i<n;++i) cout<<b[i].score<<endl; cout<<endl; delete []a; delete []b; } }
写的有点复杂了,欢迎拍砖!