| ||||||||||
| 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 | |||||||||
所谓的题解(鉴于此题代码贫瘠,所以提供AC代码)In Reply To:输入输出同样猥琐! Posted by:BAD_GUY at 2012-08-06 08:33:56 数组开到100000才有希望,字符串最好开到10
看清x是小写还是大写
最好通读一遍题
数据结构只用数组就行,少用STL(sort除外)
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
struct output {int ZIP;int cnt,bun;}O[100000];
char a[10],vil[100000][10];
bool M[100000];
int Tv,To,Tl,Tb,cnt[100000];
bool cmp(output a,output b) {
return a.ZIP<b.ZIP;
}
int main()
{
while(scanf("%s",a)!=EOF) {
if(a[0]=='?') break;
bool flag=1;
for(int i=0;i<strlen(a);i++)
if(!(a[i]>='0' && a[i]<='9')) flag=0;
bool flag2=0;
for(int i=0;i<strlen(a);i++) if(a[i]!='0') flag2=1;
if(strlen(a)!=5 || !flag || !flag2) {
for(int i=0;i<strlen(a);i++) vil[Tv][i]=a[i];
Tv++;
continue;
}
int num=0;
for(int i=0;i<strlen(a);i++) num=num*10+a[i]-'0';
cnt[num]++;
}
//puts("sdfsdf");
for(int i=10000;i<=99999;i++) if(cnt[i]>=10){
int tmp=i;
O[To].ZIP=i,O[To].cnt=cnt[i];
Tl+=cnt[i];
tmp=0;
while(cnt[i]>0) {
cnt[i]-=15;
tmp++;
}
O[To].bun=tmp;
Tb+=tmp;
To++;
cnt[i]=0;
}
sort(O,O+To,cmp);
puts("ZIP LETTERS BUNDLES\n");
for(int i=0;i<To;i++)
printf("%d%12d%12d\n",O[i].ZIP,O[i].cnt,O[i].bun);
puts("");
To=0;
for(int i=100;i<=999;i++) {
int cnt1=0;
for(int j=0;j<=99;j++) cnt1+=cnt[i*100+j];
if(cnt1>=10) {
for(int j=0;j<=99;j++) cnt[i*100+j]=0;
int tmp=i;
O[To].ZIP=i,O[To].cnt=cnt1;
Tl+=cnt1;
tmp=0;
while(cnt1>0) {
cnt1-=15;
tmp++;
}
O[To].bun=tmp;
Tb+=tmp;
To++;
}
}
sort(O,O+To,cmp);
for(int i=0;i<To;i++)
printf("%dxx%12d%12d\n",O[i].ZIP,O[i].cnt,O[i].bun);
puts("");
To=0;
for(int i=10000;i<=99999;i++) if(cnt[i]>0){
int tmp=i;
O[To].ZIP=i,O[To].cnt=cnt[i];
Tl+=cnt[i];
O[To].bun=0;
To++;
cnt[i]=0;
}
sort(O,O+To,cmp);
for(int i=0;i<To;i++)
printf("%d%12d%12d\n",O[i].ZIP,O[i].cnt,O[i].bun);
puts("");
printf("TOTALS%11d%12d\n\n",Tl,Tb);
puts("INVALID ZIP CODES\n");
for(int i=0;i<Tv-1;i++) if(!M[i])
for(int j=i+1;j<Tv;j++) if(strcmp(vil[j],vil[i])==0)
M[j]=1;
for(int i=0;i<Tv;i++) if(M[i]==0)
printf("%s\n",vil[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