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

看来只有这种水题才做得到1A,发代码

Posted by idead at 2015-09-07 13:20:51 on Problem 1035
#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool check1(string dictopt,string str);
bool check2(string dictopt, string str);
bool check3(string dictopt, string str);
int main()
{
	vector<string> dict;
	string temp;
	bool correct = true;
	while (1)
	{
	cin >> temp;
		if (temp == "#")
		{
			break;
		}
		dict.push_back(temp);
	}
	while (1)
	{
		cin >> temp;
		if (temp == "#")
		{
			break;
		}
		correct = false;
		vector<string>::iterator it;
		for (it = dict.begin(); it != dict.end(); it++)
		{
			if (temp == *it)
			{
				correct = true;
				break;
			}
		}
		if (correct == false)
		{
			cout << temp << ":";
			for (it = dict.begin(); it != dict.end(); it++)
			{
				if (check1(*it, temp) || check2(*it, temp) || check3(*it, temp))
				{
					cout << " " << *it;
				}
			}
		}else{
			cout << temp << " is correct";
		}
		cout << "\n";
	}
	return 0;
}
bool check1(string dictopt, string str)//deleting of one letter from the word; 
{
	if (dictopt.length() != str.length() + 1) return false;
	int i,j,k;
	bool match;
	for (i = 0; i < dictopt.length(); i++)
	{
		match = true;
		k = 0;
		for (j = 0; j < dictopt.length(); j++)
		{
			if (i == j) continue;
			if (dictopt[j] != str[k])
			{
				match = false;
				break;
			}
			k++;
		}
		if (match)
		{
			return true;
		}
	}
	return false;
}
bool check2(string dictopt, string str)//replacing of one letter in the word with an arbitrary letter;
{
	if (dictopt.length() != str.length()) return false;
	int i, j;
	bool match;
	for (i = 0; i < dictopt.length(); i++)
	{
		match = true;
		for (j = 0; j < dictopt.length(); j++)
		{
			if (i == j) continue;
			if (dictopt[j] != str[j])
			{
				match = false;
				break;
			}
		}
		if (match)
		{
			return true;
		}
	}
	return false;
}
bool check3(string dictopt, string str)//inserting of one arbitrary letter into the word. 
{
	if (dictopt.length()+1 != str.length()) return false;
	int i, j, k;
	bool match;
	for (i = 0; i < str.length(); i++)
	{
		match = true;
		k = 0;
		for (j = 0; j < str.length(); j++)
		{
			if (i == j) continue;
			if (str[j] != dictopt[k])
			{
				match = false;
				break;
			}
			k++;
		}
		if (match)
		{
			return true;
		}
	}
	return false;
}

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