| ||||||||||
| 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, discuss里所有推荐的数据也都试过了,还是出错,, 求高手指教方法就是暴力搜索, add,replace, delete方法
#include "stdio.h"
struct thedic{
char wordname[18];
int thelen;
}thedic_p[10100];
int i =0;
int p =0;
int x=0;
int j,count,len,mywordlen,totalnumber;
char myword[18];
char * tempword;
char* tempmyword;
char wordtopass[18];
//Replace one character
void replace(const char * wordpro,const char * dicword){
int count =0;
tempword = dicword;
tempmyword = wordpro;
for(j=0;j<strlen(tempword);j++){
if(tempmyword[j] != tempword[j])count++;
if(count > 1)return;
}
printf(" %s",tempword);
}
//Add one character to myword
void add(const char * wordpro,const char *dicword){
tempword = dicword;
tempmyword = wordpro;
for(j=0;j<strlen(tempword);j++){
if(tempmyword[j] != tempword[j]){
len = strlen(tempmyword);
tempmyword[len+2] ='\0';
while(len-- > j){
tempmyword[len+1]=tempmyword[len];
}
tempmyword[j] = tempword[j];
if(!strcmp(tempmyword,tempword)){
printf(" %s",tempword);
}
return;
}
}
return;
}
//Delete one character from myword
void deleteone(const char * wordpro,const char * dicword){
tempword = dicword;
tempmyword = wordpro;
for(j=0;j<strlen(tempmyword);j++){
if(tempmyword[j] != tempword[j]){
len = strlen(tempmyword);
if(j<(len-1)){
while(j++ < (len-1)){
tempmyword[j-1]=tempmyword[j];
tempmyword[j] ='\0';
}
}
else if(j==(len-1)){
tempmyword[j] ='\0';
}
if(!strcmp(tempmyword,tempword)){
printf(" %s",tempword);
}
return;
}
}
return;
}
int main(void) {
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#else
#endif
while(scanf("%s",thedic_p[i++].wordname)){
if(!strcmp(thedic_p[i-1].wordname,"#")){
totalnumber = i-1;
break;
}
thedic_p[i-1].thelen= strlen(thedic_p[i-1].wordname);
}
nextwords:
for(;;){
scanf("%s",myword);
if(!strcmp(myword,"#"))break;
mywordlen=strlen(myword);
for(p=0;p<totalnumber;p++){
if(!strcmp(myword,thedic_p[p].wordname)){
printf("%s is correct\n",myword);
goto nextwords;
}
}
printf("%s:",myword);
for(p=0;p<totalnumber;p++){
x=0;
while(wordtopass[x++] = myword[x++]);
wordtopass[x]='\0';
if(abs(mywordlen-thedic_p[p].thelen)>1)continue;
if(mywordlen==thedic_p[p].thelen){
replace(wordtopass,thedic_p[p].wordname);
continue;
}
if(mywordlen > thedic_p[p].thelen){
deleteone(wordtopass,thedic_p[p].wordname);
continue;
}
else{
add(wordtopass,thedic_p[p].wordname);
continue;
}
}
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