好恶心的题
#include <cstdio> #include <string.h> #include <algorithm> #include <cmath> #include <set> using namespace std; typedef __int64 ll; struct point{ ll word,priori; }P[50005]; char T[8][100]={ {"Add"},{"Close"},{"Chat"},{"Rotate"},{"Prior"},{"Choose"},{"Top"},{"Untop"}}; int sz,op,always=-1; void per(int x){ point ttt = P[x]; for(int i=x; i>0; --i) P[i]=P[i-1]; P[0]=ttt; } void last(int x){ point ttt= P[x]; for(int i=x; i<sz-1; ++i) P[i]=P[i+1]; P[sz-1]=ttt; } void solve0(){ ll id; scanf("%I64d",&id); int loc=-1; for(int i=0; i<sz; ++i) if( P[i].priori == id ){ loc=i; break; } if( loc == -1 ){ P[sz].word=0; P[sz].priori=id; sz++; printf("Operation #%d: success. ",op++); }else{ printf("Operation #%d: same priority. ",op++); } } void solve1(){ ll id; scanf("%I64d",&id); int loc=-1; for(int i=0; i<sz; ++i) if(P[i].priori==id){ loc=i; break; } if(loc==-1){ printf("Operation #%d: invalid priority. ",op++); }else { printf("Operation #%d: close %I64d with %I64d. ",op++,P[loc].priori,P[loc].word); if(P[loc].priori==always) always=-1; for(int i=loc+1; i<sz; ++i) P[i-1]=P[i]; sz--; } } void solve2(){ ll id; scanf("%I64d",&id); if(sz==0){ ///***************************** printf("Operation #%d: empty. ",op++); }else{ if(always!=-1){ for(int i=0; i<sz; ++i) if(P[i].priori==always){ P[i].word+=id; break; } }else P[0].word+= id; printf("Operation #%d: success. ",op++); } } void solve3(){ ll id; scanf("%I64d",&id); id--; if( id<0 || id >= sz){ printf("Operation #%d: out of range. ",op++); }else{ point ttt=P[id]; for(int i=id; i>0; --i) P[i]=P[i-1]; P[0]=ttt; printf("Operation #%d: success. ",op++); } } void solve4(){ if(sz==0){ printf("Operation #%d: empty. ",op++); }else{ int loc=0; ll hi=-1; for(int i=0; i<sz; ++i) if(P[i].priori>hi) hi=P[i].priori,loc=i; point ttt=P[loc]; for(int i=loc; i>0; --i) P[i]=P[i-1]; P[0]=ttt; printf("Operation #%d: success. ",op++); } } void solve5(){ ll id; scanf("%I64d",&id); int loc=-1; for(int i=0; i<sz; ++i) if(P[i].priori==id){ loc=i; break; } if(loc==-1){ printf("Operation #%d: invalid priority. ",op++); return; } point ttt=P[ loc ]; for(int i=loc; i>0; --i) P[i]=P[i-1]; P[0]=ttt; printf("Operation #%d: success. ",op++); } void solve6(){ ll id; scanf("%I64d",&id); int loc=-1; for(int i=0; i<sz; ++i) if(P[i].priori==id){ loc=i; break; } if(loc==-1){ printf("Operation #%d: invalid priority. ",op++); return; } always=id; printf("Operation #%d: success. ",op++); } void solve7(){ if(always==-1){ printf("Operation #%d: no such person. ",op++); return; } always=-1; printf("Operation #%d: success. ",op++); } int main(){ int cas; scanf("%d",&cas); char str[100]; for(int cc= 1; cc<=cas; ++cc){ int n; scanf("%d",&n); always=-1; sz=0;op=1; for(int i=0; i<n; ++i){ scanf("%s",str); if(strcmp(str,T[0])==0) solve0(); else if(strcmp(str,T[1])==0) solve1(); else if(strcmp(str,T[2])==0) solve2(); else if(strcmp(str,T[3])==0) solve3(); else if(strcmp(str,T[4])==0) solve4(); else if(strcmp(str,T[5])==0) solve5(); else if(strcmp(str,T[6])==0) solve6(); else if(strcmp(str,T[7])==0) solve7(); // printf(". "); } if(always!=-1){ for(int i=0; i<sz; ++i) if(P[i].priori==always&&P[i].word!=0){ printf("Bye %I64d: %I64d ",P[i].priori,P[i].word); break; } } for(int i=0; i<sz; ++i) if(P[i].priori!=always&&P[i].word!=0){ printf("Bye %I64d: %I64d ",P[i].priori,P[i].word); } } return 0; }