| ||||||||||
| 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 | |||||||||
vector每次分配的时候都是1.5倍的,估计string也是,这个极容易超的In Reply To:用vector<string>怎么会超内存哪? Posted by:yarrow at 2005-04-14 16:37:21 > 郁闷死了,谁能帮我看一下?
>
> #include <iostream>
> #include <string>
> #include <vector>
> using namespace std;
>
> int main()
> {
> while(1)
> {
> vector<string> dic;
> string word;
> cin>>word;
> while(word != "#")
> {
> dic.push_back(word);
> cin>>word;
> }
>
> string checked;
> cin>>checked;
> while(checked != "#")
> {
> int length = checked.length();
> vector<string> replace;
> for(int i = 0; i < dic.size(); i++)
> {
> int lengthi = dic[i].length();
> switch(lengthi-length){
> case 0:
> {
> if(dic[i] == checked)
> {
> cout<<checked<<" is correct"<<endl;
> goto END;
> }
> else // check replace
> {
> for(int j = 0; j < length; j++)
> if(checked[j] != dic[i][j])
> {
> if(j == length-1 || checked.substr(j+1) == dic[i].substr(j+1))
> replace.push_back(dic[i]);
> break;
> }
> }
> break;
> }
> case 1: // check insert
> {
> for(int j = 0; j < length; j++)
> if(checked[j] != dic[i][j])
> {
> if(checked.substr(j) == dic[i].substr(j+1))
> replace.push_back(dic[i]);
> break;
> }
> if(j == length) // insert at end
> replace.push_back(dic[i]);
> break;
> }
> case -1: // check delete
> {
> for(int j = 0; j < lengthi; j++)
> if(checked[j] != dic[i][j])
> {
> if(checked.substr(j+1) == dic[i].substr(j))
> replace.push_back(dic[i]);
> break;
> }
> if(j == lengthi) // delete at end
> replace.push_back(dic[i]);
> break;
> }
> default: // no replacement could be done
> ;
> }
> }
> END:
> if(i == dic.size()) // not correct, find replacements
> {
> cout<<checked<<':';
> if(replace.size() == 0)
> cout<<endl;
> else
> {
> for(int j = 0; j < replace.size(); j++)
> cout<<' '<<replace[j];
> cout<<endl;
> }
> }
> cin>>checked;
> }
> }
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator