Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用vector<string>怎么会超内存哪?

Posted by yarrow at 2005-04-14 16:37:21 on Problem 1035
郁闷死了,谁能帮我看一下?

#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator