| ||||||||||
| 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!!...........谁能给几组测试数据啊??本程序边进行格式处理边进行插入排序;排序用的是一个辅助数组order[]
#include <stdio.h>
int main()
{
int num[100000],order[100000];
int n,i,j,k,t=0,mark,flag,l;
char turn[26]="2223334445556667077888999";
char str[80],ch[100000][8];
scanf("%d",&n);
for(i=0;i<n;i++)
{
k=0;
mark=1;
l=t-1;
scanf("%s",str);
for(j=0;str[j]!='\0';j++)
{
flag=0;
if(k==3)
ch[t][k++]='-';
if(str[j]>='0'&&str[j]<='9')
{
flag=1;
ch[t][k++]=str[j];
}
else if(str[j]>='A'&&str[j]<'Z')
{
flag=1;
ch[t][k++]=turn[str[j]-'A'];
}
if(mark&&flag)//进行比较
{
while(l>=0&&ch[t][k-1]<ch[order[l]][k-1])
l--;
if(l>=0&&ch[t][k-1]>ch[order[l]][k-1])
mark=0;
}
}
if(mark==1&&l>=0)//相等时直接加1
num[order[l]]++;
else//否则调整order[]顺序,进行插入
{
for(k=t;k>l+1;k--)
order[k]=order[k-1];
order[l+1]=t;
num[t]=1;
t++;
}
}
flag=1;
for(j=0;j<t;j++)
{
if(num[order[j]]>1)
{
flag=0;
for(i=0;i<8;i++)
printf("%c",ch[order[j]][i]);
printf(" %d\n",num[order[j]]);
}
}
if(flag)
printf("No duplicates.\n");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator