d518.
文字抄寫 II
| From: [58.19.246.33] |
發表日期
:
2010-11-12 20:21
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct node
{
int No;
char name[21];
}node;
node p[26][10001];
int pn[26],flag,x;
int insert(const char *s,node *a,int low,int high)
{
int mid,i;
if (high==0) { pn[s[0]-'a']=1; a[1].No=++x; strcpy(a[1].name,s); flag=0; return x; }
while (low<=high)
{
mid=(low+high)/2;
i=strcmp(s,a[mid].name);
if (i==0) { flag=1; return a[mid].No; }
else if (i==-1) high=mid-1;
else low=mid+1;
}
for (i=pn[s[0]-'a'];i>=low;i--) a[i+1]=a[i];
strcpy(a[low].name,s);
a[low].No=++x;
pn[s[0]-'a']++;
flag=0;
return x;
}
int main()
{
int n,k,i;
char s[21];
while (scanf("%d",&n)==1)
{
x=0;
memset(pn,0,sizeof(pn));
for (i=0;i<n;i++)
{
scanf("%s",s);
k=insert(s,p[s[0]-'a'],1,pn[s[0]-'a']);
if (flag) printf("Old! %ld\n",k);
else printf("New! %ld\n",k);
}
}
return 0;
}
——————————————————————————————————————————
與正確輸出不相符(line:173)
您的答案為: New! 161
正確答案為: Old! 129
如果超时还可理解,WA,实在郁闷!能否给出这一组的测资?