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 |
实在找不到哪里WA的。。救命啊,附代码# include <iostream> using namespace std; # include <set> # include <vector> class point { public: char *str; int num; int letter; point():num(1),letter(0){} }; class cmp5 { public: bool operator ()(const point &pos1,const point &pos2) const { char temp1[10],temp2[10]; char *a=pos1.str,*b=pos2.str; for(int i=0;i<5;i++) { temp1[i]=a[i]; temp2[i]=b[i]; } temp1[5]=temp2[5]='\0'; if(strcmp(temp1,temp2)==-1) return 1; else return 0; } }; class cmp3 { public: bool operator ()(const point &pos1,const point &pos2) const { char temp1[10],temp2[10]; char *a=pos1.str,*b=pos2.str; for(int i=0;i<3;i++) { temp1[i]=a[i]; temp2[i]=b[i]; } temp1[3]=temp2[3]='\0'; if(strcmp(temp1,temp2)==-1) return 1; else return 0; } }; set<point,cmp5> refer1; set<point,cmp3> refer2; vector<char *> invalid; vector<point> b5,b3,oth; int c=0; inline int search(int num) { if(num%15==0) return num/15; else return num/15+1; } bool chk(char *pos) { if(strlen(pos)!=5) return 0; for(int i=0;i<5;i++) { if(pos[i]>'9'||pos[i]<'0') return 0; } bool flag=0; for(int i=0;i<5;i++) if(pos[i]!=48) { flag=1; break; } return flag; } bool find(char *temp) { for(int i=0;i<invalid.size();i++) { if(!strcmp(invalid[i],temp)) return 1; } return 0; } int main() { char *temp=new char[100]; while(scanf("%s",temp)!=EOF) { // if(strcmp(temp,"0")==0) break; if(!chk(temp)) {if(!find(temp)) invalid.push_back(temp);} else { point ins; ins.str=temp; set<point,cmp5>::iterator it=refer1.find(ins); if(it==refer1.end()) refer1.insert(ins); else (it->num)++; } temp=new char[100]; } for(set<point,cmp5>::iterator it=refer1.begin();it!=refer1.end();it++) { if(it->num>=10) { if(it->num>=20) { point pos=*it; pos.num=search(pos.num); pos.letter=it->num; it->num=0; b5.push_back(pos); } else if(it->num<=15) { point pos=*it; pos.num=1; pos.letter=it->num; it->num=0; b5.push_back(pos); } else { point pos=*it; pos.num=1; it->num-=15; pos.letter=15; b5.push_back(pos); } } } for(set<point,cmp5>::iterator it=refer1.begin();it!=refer1.end();it++) { if(it->num!=0) { set<point,cmp3>::iterator ins=refer2.find(*it); if(ins==refer2.end()) refer2.insert(*it); else ins->num+=it->num; } } for(set<point,cmp3>::iterator it=refer2.begin();it!=refer2.end();it++) { if(it->num>=10) { if(it->num>=20) { point pos=*it; pos.num=search(pos.num); pos.letter=it->num; it->num=0; b3.push_back(pos); } else if(it->num<=15) { point pos=*it; pos.num=1; pos.letter=it->num; it->num=0; b3.push_back(pos); } else { point pos=*it; pos.num=1; it->num-=15; pos.letter=15; b3.push_back(pos); } } } for(set<point,cmp3>::iterator it=refer2.begin();it!=refer2.end();it++) { if(it->num) { point pos=*it; pos.num=0; pos.letter=it->num; oth.push_back(pos); } } //print int tl=0,tn=0; printf("ZIP LETTERS BUNDLES\n\n"); for(int i=0;i<b5.size();i++) {printf("%s%12d%12d\n",b5[i].str,b5[i].letter,b5[i].num);tl+=b5[i].letter;tn+=b5[i].num;} printf("\n"); for(int i=0;i<b3.size();i++) {printf("%c%c%cxx%12d%12d\n",b3[i].str[0],b3[i].str[1],b3[i].str[2],b3[i].letter,b3[i].num);tl+=b3[i].letter;tn+=b3[i].num;} printf("\n"); for(int i=0;i<oth.size();i++) {printf("%s%12d%12d\n",oth[i].str,oth[i].letter,oth[i].num);tl+=oth[i].letter;tn+=oth[i].num;} printf("\nTOTALS%11d%12d\n",tl,tn); printf("\nINVALID ZIP CODES\n\n"); for(int i=0;i<invalid.size();i++) printf("%s\n",invalid[i]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator