PersonalCorpus 版 (精华区)
1140013 Big Guava ... 10336 Accepted
0:00.000 64 2002/10/03 06:54:27.210
const int p[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
char ch[26],map[1000][1000],tt;
int sum[26],a,b;
void tryit (int x, int y)
{
int u,v,i;
map[x][y]='.';
for (i=0;i<4;i++) {
u=p[i][0]+x;
v=p[i][1]+y;
if (((u>=0)&&(u<a))&&((v>=0)&&(v<b))&&(map[u][v]==tt)) tryit(u,
v);
}
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\0acm\\uva\\i10336","r",stdin);
freopen("c:\\0acm\\uva\\o10336","w",stdout);
#endif
int i,j,k,n,t;
scanf("%d\n",&n);
for (t=1;t<=n;t++) {
printf("World #%d\n",t);
scanf("%d%d\n",&a,&b);
for (i=0;i<a;i++) gets(map[i]);
for (i=0;i<26;i++) ch[i]=i+97;
memset(sum,0,sizeof(sum));
for (i=0;i<a;i++) for (j=0;j<b;j++) if(map[i][j]!='.') {
tt=map[i][j];
sum[tt-97]++;
tryit(i,j);
}
for (i=0;i<25;i++) for (j=i+1;j<26;j++)
if ((sum[i]<sum[j])||((sum[i]==sum[j])&&(ch[i]>ch[j]))) {
k=sum[i]; sum[i]=sum[j]; sum[j]=k;
tt=ch[i]; ch[i]=ch[j]; ch[j]=tt;
}
for (i=0;i<26;i++) if (sum[i]!=0) printf("%c: %d\n",ch[i],
sum[i]);
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.222毫秒