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呢?高手请看!#include <iostream.h> #include <string.h> char * pDic [10000]; int numOfWords; void Dic () { numOfWords = 0; char buff[20]; cin >> buff; while ( buff [0] != '#' ) { pDic [numOfWords] = new char [ strlen ( buff ) + 1 ]; strcpy ( pDic [numOfWords], buff ); numOfWords++; cin >> buff; } } void Check ( char * word ) { for ( int j = 0; j < numOfWords; j++ ) if ( strcmp ( pDic [j], word ) == 0 ) { cout << word << " is correct\n"; return; } cout << word << ":"; for ( int i = 0; i < numOfWords; i++ ) { int len = strlen ( word ); int p, pWord; switch ( strlen ( pDic [i] ) - len ) { case 1: p = 0, pWord = 0; while ( pDic [i][p] == word [pWord] ) { p++; pWord++; } p++; while ( pDic [i][p] == word [pWord] && pDic && p ) { p++; pWord++; } if ( p == len + 2 ) cout << " " << pDic [i]; break; case -1: p = 0, pWord = 0; while ( pDic [i][p] == word [pWord] ) { p++; pWord++; } pWord++; while ( pDic [i][p] == word [pWord] ) { p++; pWord++; } if ( pWord == len + 1 ) cout << " " << pDic [i]; break; case 0: p = 0, pWord = 0; while ( pDic [i][p] == word [pWord] ) { p++; pWord++; } pWord++; p++; while ( pDic [i][p] == word [pWord] ) { p++; pWord++; } if ( pWord == len + 1 ) cout << " " << pDic [i]; } } cout << endl; } void main() { Dic (); char word [20]; cin >> word; while ( word [0] != '#' ) { Check ( word ); cin >> word; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator