标签:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 23998 | Accepted: 8754 |
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
#include<cstdio> #include<iostream> #include<string.h> using namespace std; #define N 50 char dict[N*200+1][16]; char word[N+1][16]; int dictnum=0; //字典计数器 int wordnum=0; //单词计数器 int change(char* word,char* dict)//检查字符串word能否通过变换得到dict {//wordLen==dictlen int dif=0; //记录word与dict中在相同位置出现不同字符的个数 while(*word){ if(*(word++)!=*(dict++)){ dif++; if(dif>1) return 0; } } return 1; } int del(char* word,char* dict)//检查字符串word能否通过删除得到dict {//wordLen==dictlen+1 int dif=0; //记录word与dict中在对应位置出现不同字符的个数 while(*word){ if(*word!=*dict){ word++;dif++; //word后移一位再匹配 if(dif>1) return 0; } else word++,dict++; } return 1; } int add(char* word,char* dict)//检查字符串word能否通过添加得到dict {//wordLen==dictlen-1 int dif=0; //记录word与dict中在对应位置出现不同字符的个数 while(*dict){ if(*word!=*dict){ dict++;dif++; //dict后移一位再匹配 if(dif>1) return 0; } else word++,dict++; } return 1; } int main() { while(cin>>dict[dictnum] && dict[dictnum++][0]!=‘#‘);dictnum--; while(cin>>word[wordnum] && word[wordnum++][0]!=‘#‘);wordnum--; int* dictlen=new int[dictnum]; //记计算字典中各个单词的长度 for(int i=0;i<dictnum;i++) dictlen[i]=strlen(dict[i]); for(int i=0;i<wordnum;i++){ int* address=new int[dictnum]; //记录word[i]通过变化得到的单词在dict中的下标 int pa=0; //address指针 int flag=0; //标记字典中是否含有单词word[i] int len=strlen(word[i]); for(int k=0;k<dictnum;k++){//遍历字典 if(dictlen[k]==len){ //change or Equal if(!strcmp(word[i],dict[k])){ flag=1;break; } else if(change(word[i],dict[k])) address[pa++]=k; } else if(len-dictlen[k]==1){ //delete if(del(word[i],dict[k])) address[pa++]=k; } else if(dictlen[k]-len==1){ //add if(add(word[i],dict[k])) address[pa++]=k; } } if(flag) cout<<word[i]<<" is correct"<<endl; else{ cout<<word[i]<<": "; for(int j=0;j<pa;j++) cout<<dict[address[j]]<<‘ ‘; cout<<endl; } delete address; } return 0; }
标签:
原文地址:http://www.cnblogs.com/shenben/p/5619523.html