Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
OTZOTZIn Reply To:感觉没啥问题,为什么总过不了呢??是哪部分细节?还是输出问题??谢谢 Posted by:whosyourdaddy at 2006-10-26 10:50:17 > #include <iostream> > #include <bitset> > #include <string> > #include <iomanip> > #include <cstdlib> > > using namespace std; > > const int size=60; > int score[10]={15,12,9,7,6,5,4,3,2,1}; > > bitset<size> bit; > int order[10]; > > struct teacher{ > string name; > string depart; > int voteboard[10]; > int score; > int vote; > int id; > } Teach[size]; > > bool check(string&, int ); > void collect(); > void output(); > > int compare(const void* a, const void* b) > { > const teacher* x=(const teacher*)a; > const teacher* y=(const teacher*)b; > if(x->score > y->score) > return -1; > else if(x->score == y->score) > { > if(x->vote > y->vote) > return -1; > else if(x->vote == y->vote) > { > if(x->id < y->id) > return -1; > } > } > return 1; > } > > > void main() > { > string vote; > int NumTer,NumStu; > int i,j,k; > int id; > for(i=0;i<size;i++) > Teach[i].id=i; > cin>>NumTer; > while(NumTer!=-1) > { > cin>>NumStu; > for(i=0;i<NumTer;i++)//输入并初始化 > { > cin>>id; > cin>>Teach[id].name>>Teach[id].depart; > memset(Teach[id].voteboard, 0, sizeof(Teach[id].voteboard) ); > Teach[id].score=0;Teach[id].vote=0; > } > for(j=0;j<NumStu;j++) > { > cin>>vote; > if(check(vote, NumTer)) > collect(); > } > Teach[0].score=-1;Teach[0].vote=-1;//第0个元素不用,置为最小 > qsort(Teach,NumTer+1,sizeof(Teach[0]),compare); > output(); > cin>>NumTer; > } > } > > bool check(string &vote, int NumTer) > { > bit.reset();//初始化 > int num=0; > int ptr=0; > int i; > for(i=0;i<20;i++) > { > num*=10; > num+=vote[i]-'0'; > if(i%2==1) > { > if( num>NumTer || (num!=0 && bit.test(num)==true) ) > { > return false; > } > else > bit.set(num); > order[ptr++]=num; > num=0; > } > } > return true; > } > > void collect() > { > int i; > for(i=0;i<10;i++) > { > Teach[order[i]].voteboard[i]++; > Teach[order[i]].vote++; > Teach[order[i]].score+=score[i]; > } > } > > void output() > { > int i,j; > for(i=0;i<10;i++) > { > cout<<setiosflags(ios::left)<<setw(4)<<i+1<<resetiosflags(ios::left)<<setfill('0')<<setw(2)<<Teach[i].id<<" " > <<setiosflags(ios::left)<<setfill(' ')<<setw(15)<<Teach[i].name<<setw(41) > <<Teach[i].depart<<setw(7)<<Teach[i].score<<setw(6)<<Teach[i].vote; > for(j=0;j<9;j++) > cout<<setw(6)<<Teach[i].voteboard[j]; > cout<<Teach[i].voteboard[j]; > cout<<endl; > } > } > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator