| ||||||||||
| 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的程序,那位高手指点一下?In Reply To:这题有什么要注意的?我为什么总wa? Posted by:Multistar at 2003-10-17 20:21:23 #include<stdio.h>
#include<string.h>
#define MAXW 200
#define MAXLEN 60
typedef
struct
{
int len;
char word[MAXLEN];
char num[MAXLEN];
}tword;
tword list[MAXW];
int N;
char map[26]={'2','2','2','3','3','3',
'4','4','4','5','5','5','6','6','6','7',
'7','7','7','8','8','8','9','9','9','9'};
char input[500],lin;
int res[500],nr;
int getdata()
{
int i,j,k;
tword tmp;
char cr[5];
scanf("%d",&N);
if (N==0) return 0; gets(cr);
for (i=1; i<=N; i++)
{
scanf("%s",list[i].word);
list[i].len=strlen(list[i].word);
for (j=0; j<list[i].len; j++)
list[i].num[j]=map[list[i].word[j]-'a'];
}
scanf("%s",input);
lin=strlen(input);
nr=0;
for (i=1; i<N; i++)
{
k=i;
for (j=i+1; j<=N; j++)
if (strcmp(list[k].word,list[j].word)>0) k=j;
if (k!=i)
{tmp=list[k]; list[k]=list[i]; list[i]=tmp;}
}
return 1;
}
void outres()
{
int i;
printf("%s",list[res[1]].word);
for (i=2; i<=nr; i++) printf(" %s",list[res[i]].word);
printf(".\n");
}
int match(int n,int p)
{
int i;
for (i=0; i<list[n].len; i++)
if (list[n].num[i]!=input[p+i]) return 0;
return 1;
}
void search(int p)
{
int index[200];
int i;
if (p==lin) { outres(); return ; }
for (i=1; i<=N; i++)
if (match(i,p))
{
res[++nr]=i;
search(p+list[i].len);
nr--;
}
}
int main()
{
while(getdata())
{
search(0);
printf("--\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