poj 1035(Wrong Answer)

这次是Wrong Answer...

自己测数据倒是对

太菜了。。。

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

//#define _debbug

//全局数据
vector<string> dic(100000,"")         ;
vector<string> checkwords(5000,"")    ;
vector<string> alphabet(26) ;



bool found(string temp)
{
	int testnum = 0;
	for (string testdic = dic[testnum] ; testdic != "" ; testdic = dic[testnum])
	{
		if (temp == testdic)
		{
			return true ;
		}
		else
			testnum++ ;
	}
	return false ;
}

void match()
{
	int ceshi = 0 ;
	for (string testdic = checkwords[ceshi] ; testdic != "" ; testdic = checkwords[ceshi])
	{
		if (found(testdic))
		{
			cout<<testdic<<"  is correct"<<endl ;
			ceshi++  ;
			continue ;
		}
		else
		{
			cout<<testdic<<": " ;
			//情况一,删除一个字符
			for (int i = 0 ; i < testdic.size() ; ++i)
			{
				string deletemp = testdic ;
				deletemp.erase(i,1) ;
				if (found(deletemp))
				{
					cout<<deletemp<<" " ;
				}

			}
			//情况二,替换其中一个字符
			for (int j = 0 ; j < testdic.size() ; ++j)
			{
				string replacetemp = testdic ;
				for (int jj = 0 ;jj < 26 ; ++jj)
				{
					replacetemp.replace(j,1,alphabet[jj]) ;
					if (found(replacetemp))
					{
						cout<<replacetemp<<" " ;
					}
				}
			}
			//情况三,插入其中一个字符
			for (int k = 0 ; k <= testdic.size(); ++k)
			{
				string inserttemp = testdic ;
				for (int kk = 0 ;kk < 26 ; ++kk)
				{
					string inserttemp = testdic ;
					inserttemp.insert(k,alphabet[kk]) ;
					if (found(inserttemp))
					{
						cout<<inserttemp<<" " ;
					}
				}
			}
			ceshi++ ;
			cout<<endl ;
		}
	}

}

int main()
{
	//重定向
#ifdef _debbug
	streambuf *backup1;	
	ifstream  fin;
	fin.open ("F:\\input.txt" ,ios::in  );
	backup1 = cin.rdbuf() ;    // back up cin's streambuf
	cin.rdbuf( fin.rdbuf() ) ; // assign file's streambuf to cin
#endif	
//
	alphabet[0] = "a" ;alphabet[1] = "b" ;alphabet[2] = "c" ;alphabet[3] = "d" ;alphabet[4] = "e" ;alphabet[5] = "f" ;alphabet[6] = "g" ;
	alphabet[7] = "h" ;alphabet[8] = "i" ;alphabet[9] = "j" ;alphabet[10] = "k" ;alphabet[11] = "l" ;alphabet[12] = "m" ;alphabet[13] = "n" ;
	alphabet[14] = "o" ;alphabet[15] = "p" ;alphabet[16] = "q" ;alphabet[17] = "r" ;alphabet[18] = "s" ;alphabet[19] = "t" ;alphabet[20] = "u" ;
	alphabet[21] = "v" ;alphabet[22] = "w" ;alphabet[23] = "x" ;alphabet[24] = "y" ;alphabet[25] = "z" ;
//数据初始化

	dic.reserve(10000) ;
	checkwords.reserve(50) ;
	string temp = "" ;	
	int cnt = 0 ;
	while (temp != "#")
	{
		cin >> temp ;
		if (temp == "#")
			break ;
		dic[cnt++] = temp ;
	}
		
	int start = 0 ;
	temp = "" ;
	while (temp != "#")
	{
		cin >> temp ;
		if (temp == "#")
			break ;
	    checkwords[start++] = temp;
	}
	
//执行函数
	//匹配
	match() ;

//输出结果
/*
	for (int kk= 0 ;kk <26 ; kk++)
	{
		cout <<endl << alphabet[kk];
	}
*/

//解除重定向关闭文件
#ifdef _debbug
	cin.rdbuf(backup1) ;     // restore cin's original streambuf
	fin.close();
#endif
	return 0 ;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值