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 |
Re:求大神帮帮忙啊!不想再wrong啦,测试数据全都正确,包括Discuss里的数据In Reply To:求大神帮帮忙啊!不想再wrong啦,测试数据全都正确,包括Discuss里的数据 Posted by:hejunfei at 2011-07-13 20:34:27 > 贴代码: > #include <iostream> > #include <string> > using namespace std; > > char diction[10010][20]; > int id_hold[10010]; > int size,id; > > bool replace_one( char a[], char d[], int len )//lenth相同时,只要字符不同的位置为1即可 > { > int i,count; > for ( i = count = 0; i < len; i++ ){ > if ( a[i] != d[i] ) count++; > } > if ( count > 1 ) return false; > else return true; > } > bool ins_del( char a[], char d[], int len )//当长度差1的时候,把待查单词的delete当成字典单词的insert处理,先循环找到字符不同的位置,之后内部继续循环看对应位置是否相同 > { > int i; > for ( i = 0; i < len; i++ ) > { > if ( a[i] != d[i] ){ > for ( int j = i; j < len; j++ ) > { > if ( a[j] != d[j+1] ) > return false; > } > return true; > } > } > return true; > } > bool control(char a[])// 这是一个主要的控制程序 > { > int i,result; > int len = strlen(a); > for ( i = 0; i < size; i++ ) > { > if ( len == strlen(diction[i])) > { > result = strcmp( a,diction[i] ); > if (!result) return true; > else if ( replace_one(a,diction[i],len) ) > id_hold[id++] = i; > } > else if ( len == strlen(diction[i])-1 ) > { > if ( ins_del(a,diction[i],len) ) > id_hold[id++] = i; > } > else if ( len == strlen(diction[i])+1 ) > { > if ( ins_del(diction[i],a,len-1) ) > id_hold[id++] = i; > } > } > return false; > } > > > int main() > { > int i; > char words[20]; > > i = 0; > while(true)//最后还希望看一下输入输出是否正确 > { > scanf("%s",diction[i]); > if ( strcmp(diction[i],"#") == 0 ) > break; > i++; > } > size = i; > while(true) > { > scanf("%s",words); > if ( strcmp(words,"#") == 0 ) > break; > memset(id_hold,-1,sizeof(id_hold)); > id = 0; > if (control(words)) > printf("%s is corrct\n",words); > else { > printf("%s:",words); > for ( i = 0; i < id; i++ ) > { > printf(" %s",diction[id_hold[i]]); > } > putchar('\n'); > } > } > return 0; > } correct 写错了 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator