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 |
请巨牛帮忙:咋会runtime Error??#include<iostream> #include<vector> #include<string> #include<algorithm> #include<cctype> using namespace std; struct Range{ int begin; int end; Range():begin(-1),end(-1){} }; int getNum(string& s){ return (s[0]-97);} void lookUp(string&,vector<string>&,vector<Range>&); void changeIt(string&,vector<string>&); void replaceIt(string&,string&); void addIt(string&,string&); void deleteIt(string&,string&); int main(){ cout<<"Enter your right string to dictionary\n"; string s; vector<string>dictionary; while(getline(cin,s)&&s!="#") dictionary.push_back(s); sort(dictionary.begin(),dictionary.end()); vector<Range>line(24); for(unsigned int i=0;i<=dictionary.size()-1;i++) if(line[getNum(dictionary[i])].begin==-1){ line[getNum(dictionary[i])].begin=i; line[getNum(dictionary[i])].end=i; } else line[getNum(dictionary[i])].end++; cout<<"Enter the bubble word:\n"; vector<string>customer; while(getline(cin,s)&&s!="#") customer.push_back(s); for(unsigned int i=0;i<=customer.size()-1;i++) lookUp(customer[i],dictionary,line); } void lookUp(string&word,vector<string>&dictionary,vector<Range>&line){ if(line[getNum(word)].begin>=0) for(int i=line[getNum(word)].begin;i<=line[getNum(word)].end;i++) if(word==dictionary[i]){ cout<<word<<" is correct\n"; return; } else if(word<dictionary[i]){ changeIt(word,dictionary); return; } else ; changeIt(word,dictionary); return; } void changeIt(string&word,vector<string>&dictionary){ cout<<word<<': '; for(unsigned int i=0;i<=dictionary.size()-1;i++) if(word.size()==dictionary[i].size()) replaceIt(word,dictionary[i]); else if(word.size()+1==dictionary[i].size()) addIt(word,dictionary[i]); else if(word.size()==dictionary[i].size()+1) deleteIt(word,dictionary[i]); else ; cout<<'\n'; } void replaceIt(string&word,string&answer){ bool flag=false; for(unsigned int i=0;i<=word.size()-1;i++){ if(!flag&&word[i]!=answer[i]){ i++; flag=true; } if(flag&&word[i]!=answer[i]) return; } cout<<' '<<answer; } void addIt(string&word,string&answer){ unsigned int i=0; for(;i<=word.size()-1;i++) if(word[i]!=answer[i]) break; for(unsigned int j=i;j<=word.size()-1;j++) if(word[j]!=answer[j+1]) return; cout<<' '<<answer; } void deleteIt(string&word,string&answer){ unsigned int i=0; for(;i<=answer.size()-1;i++) if(word[i]!=answer[i]) break; for(unsigned int j=i;j<=answer.size()-1;j++) if(word[j+1]!=answer[j]) return; cout<<' '<<answer; } 在visual studio上都好好的,结果为何就runtime error呢?实在不懂。。。。到底是出现溢出, 还是。。。。但为何在studio上都行呢? Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator