字符数组开小了wa好多次。。。。pe一次 哎水题
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 22862 | Accepted: 8314 |
Description
Input
Output
Sample Input
i is has have be my more contest me too if award # me aware m contest hav oo or i fi mre #
Sample Output
me is correct aware: award m: i my me contest is correct hav: has have oo: too or: i is correct fi: i mre: more me
Source
[Submit] [Go#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define maxn 10000+5
using namespace std;
struct Note{
char word[20];
}my[maxn];
int n=0;
char t[20];
char txt[maxn][20];
int tlen[maxn];
Note *pos;
int cmp(const void *a,const void *b){
return strcmp(((Note*)a)->word,((Note*)b)->word);
};
int bcmp(const void *a,const void *b){
return strcmp(((char*)a),((Note*)b)->word);
};
bool fun1(char *a,char *b,int l){
int cnt=0;
for(int i=0;i<l;++i){
if(a[i]==b[i])
cnt++;
}
if(cnt+1==l)return true;
return false;
};
bool fun2(char *a,char *b){
int flag=0;
while(*a){
if(*a!=*b){
b++;
flag++;
if(flag>1)
return false;
}
else {
a++;
b++;
}
}
return true;
};
int main(){
int n=0;
while(scanf("%s",txt[n])!=EOF&&strcmp("#",txt[n])){
strcpy(my[n].word,txt[n]);
tlen[n]=strlen(txt[n]);
n++;
}
qsort(my,n,sizeof(Note),cmp);
while(scanf("%s",t)!=EOF&&strcmp("#",t)){
pos=(Note*)bsearch(t,my,n,sizeof(Note),bcmp);
if(pos)printf("%s is correct\n",pos->word);
else{
printf("%s:",t);
int len=strlen(t);
for(int i=0;i<n;++i){
if(len+1==tlen[i]){
if(fun2(t,txt[i]))
printf(" %s",txt[i]);
}
else if(len==tlen[i]){
if(fun1(t,txt[i],len))
printf(" %s",txt[i]);
}
else if(len-1==tlen[i]){
if(fun2(txt[i],t))
printf(" %s",txt[i]);
}
}
putchar('\n');
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/zp___waj/article/details/47807489