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> #include<string> #include<vector> #include<fstream> using namespace std; vector<string> Key; vector<string> Resemble;//近似数组存储与所测试对象近似的串 int A[2][16]; int Test(string ); bool replace(string A,string B); int main( ) { string a; ifstream ii("TextFile1.txt",ios::in); if(!ii) { return 1; } while(ii>>a&&a!="#") { Key.push_back(a); } while(ii>>a&&a!="#") { Test(a); } ii.close(); system("pause"); return 0; } int Test(string a) { Resemble.clear(); int k=0; int Size=Key.size(); /*int m=a.size(); int n=0;*/ for(int i=0;i<Size;i++) { if(a==Key[i]) { cout<<a<<' '<<"is"<<' '<<"correct"<<endl; return 0; } else { if(replace(a,Key[i]) ) { Resemble.push_back(Key[i]); } } } cout<<a<<':'; for(int j=0;j<Resemble.size();j++) cout<<' '<<Resemble[j]; cout<<endl; return 0; } bool replace(string A,string B) { int l1=A.size(); int l2=B.size(); int i=0; if(l1==l2) { while(i<l1&&A[i]==B[i]) i++; while(++i<l1) if(A[i]!=B[i]) return false; }else if(l1==l2+1) { while(i<l2&&A[i]==B[i]) i++; while(++i<l1) if(A[i]!=B[i-1]) return false; }else if(l1+1==l2) { while(i<l1&&A[i]==B[i]) i++; while(++i<l2) if(A[i-1]!=B[i]) return false; }else return false; return true; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator