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 |
请牛人看一下,不知哪错了? poj1035#include<iostream> #include<string> #include<stdio.h> #define max1 10001 #define max2 51 using namespace std; char dict[max1][16]; char check[max2][16]; int ch[max2]; int search(char* a,char *b); int delet(char * a,char *b); int replace(char * a,char * b); int insert(char * a,char * b); int main() { // freopen("poj.txt","r",stdin); memset(ch,0,max2); int d=0; while(dict[d-1][0]!='#') { scanf("%s\n",dict[d]); d++; } int r=0; while(check[r-1][0]!='#') { scanf("%s\n",check[r]); r++; } for(int i=0;i<r-1;i++) { int len=strlen(check[i]); for(int k=0;k<len;k++) printf( "%c",check[i][k]); for(int j=0;j<d-1;j++) { if(search(dict[j],check[i])) { printf(" is correct"); printf("\n"); ch[i]=1; } } if(!ch[i]) { cout<<":"; for(int jj=0;jj<d-1;jj++) { if(replace(dict[jj],check[i])) { int lenn=strlen(dict[jj]); cout<<" "; for(int kk=0;kk<lenn;kk++) cout<<dict[jj][kk]; } if(delet(dict[jj],check[i])) { int lenm=strlen(dict[jj]); cout<<" "; for(int km=0;km<lenm;km++) cout<<dict[jj][km]; } if(insert(dict[jj],check[i])) { int lenb=strlen(dict[jj]); cout<<" "; for(int kb=0;kb<lenb;kb++) cout<<dict[jj][kb]; } } printf("\n"); } } return 0; } int search(char * a,char*b) //判断词典是否有这个词 { int i; int bj=1; int len1=strlen(a); int len2=strlen(b); if(len1==len2) { bj=0; for( i=0;i<len1;i++) if(a[i]!=b[i]) bj=1; } if(bj==0) return 1; else return 0; } int delet(char *a,char *b) //判断删除错误 { int j; int len1=strlen(a); int len2=strlen(b); if(len1==len2+1) { for(j=0;j<len1;j++) { int sum=0; int i=0; while(i<j && i>=0 ) { if(a[i]==b[i]) sum=sum+1; i++; } i=j+1; while(i<len1 && i>j) { if(a[i]==b[i-1]) sum=sum+1; i++; } if(sum==len2) { return 1; break; } } } return 0; } int replace(char * a,char *b) //替换错误 { int len1=strlen(a); int len2=strlen(b); if(len1==len2) { int bz=0; for(int i=0;i<len1;i++) if(a[i]!=b[i]) bz=bz+1; if(bz==1) { return 1; } } return 0; } int insert(char *a,char *b ) //插入错误 { int bj=1; int j; int len1=strlen(a); int len2=strlen(b); if(len1==len2-1) { bj=0; for(j=0;j<len2;j++) { int sum=0; int i=0; while(i<j && i>=0 ) { if(a[i]==b[i]) sum=sum+1; i++; } i=j+1; while(i<len2 && i>j) { if(b[i]==a[i-1]) sum=sum+1; i++; } if(sum==len1) { return 1; break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator