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 |
提交了N次,改了N次,还是Runtime Error,请高手帮忙,拜托!!!#include<iostream> #include<string> #include<algorithm> using namespace std; #define maxlen 500000 int Dictionary[26][maxlen]; string WordOrder[10001]; int Sign[maxlen]; int COUNT=1; int nMod=0; int ModifiedAs[50]; void create_dict() { COUNT=1; string s; int i=1; cin>>s; while(s!="#") { WordOrder[i]=s; int last_data=Dictionary[s[0]-'a'][0]; if(last_data==0) { Dictionary[s[0]-'a'][0]=COUNT; } for(int j=1;s[j]!='\0';j++) { if(last_data!=0) { while(Dictionary[s[j]-'a'][last_data]!=0) {last_data=Dictionary[s[j]-'a'][last_data];j++;} Dictionary[s[j]-'a'][last_data]=++COUNT; last_data=Dictionary[s[j]-'a'][last_data]; } else { Dictionary[s[j]-'a'][COUNT]=++COUNT; } } Sign[COUNT++]=i; i++; cin>>s; } } int check(string s) { int k=0,i=0; while(s[i]!='\0') { k=Dictionary[s[i]-'a'][k]; if(k!=0) {i++;} else { break; return 0; } } return Sign[k]>0?Sign[k]:0; } void deleting(string s,int position) { string s1=s.erase(position,1); int i=check(s1); if(i>0) ModifiedAs[nMod++]=i; } void replacing(string s,int position) { string s0; for(char c='a';c<='z';c++) { s0=s; string s1=s0.replace(position,1,1,c); int i=check(s1); if(i>0) ModifiedAs[nMod++]=i; } } void inserting(string s,int position) { string s0; for(char c='a';c<='z';c++) { s0=s; string s1=s0.insert(position,1,c); int i=check(s1); if(i>0) ModifiedAs[nMod++]=i; } } int main() { create_dict(); string s; cin>>s; while(s!="#") { int k=check(s); if(k>0) { cout<<s<<" is correct"<<endl; cin>>s; } else { cout<<s<<": "; int len=s.size(); /**/for(int i=0;i<len;i++) { deleting(s,i); } for(int i=0;i<len;i++) { replacing(s,i); } for(int i=0;i<len+1;i++) { inserting(s,i); } sort(ModifiedAs,ModifiedAs+nMod); for(int i=0;i<nMod;i++) { if(ModifiedAs[i]==ModifiedAs[i+1]) ModifiedAs[i]=0; } for(int i=0;i<nMod;i++) { if(ModifiedAs[i]!=0) cout<<WordOrder[ModifiedAs[i]]<<" "; } cout<<endl; for(int i=0;i<nMod+1;i++) { ModifiedAs[i]=0; } nMod=0; cin>>s; } } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator