码迷,mamicode.com
首页 > 其他好文 > 详细

hdu oj 4300 Clairewd’s message AC code

时间:2015-06-17 21:36:50      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<vector>
#include<cassert>

using namespace std;

int main(void)
{
	int T;
	cin >> T;
	while (T--) {
		string S, msg;
		while (cin >> S >> msg) {
			//assume division point.
			int div = (msg.length())/ 2;
		
			//cout << div << endl;

			//partial decryption.
			string pmsg(msg.begin(), msg.begin()+div);
			for (int i = 0; i < pmsg.length(); ++i) {
				pmsg[i] = 'a'+S.find(pmsg[i]);
			}

			//cout << pmsg << endl;

			//pinpoint the division point.
			int pos;
			for (pos = div; pos < msg.length(); ++pos) {
				if (msg.compare(pos, msg.length() - pos, pmsg.c_str(),msg.length() - pos) == 0)
					break;
			}
			

			cout << msg.substr(0, pos);
			for (int i = 0; i < pos; ++i) {
				cout << (char)('a' + S.find(msg[i]));
			}
			cout << endl;
		}
	}
	//system("pause");
	return 0;
}

hdu oj 4300 Clairewd’s message AC code

标签:

原文地址:http://blog.csdn.net/qq_21555605/article/details/46537547

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!