hdu oj 4300 Clairewd’s message AC code

本文介绍了一个基于字符串操作的解密算法实现。通过读取输入的字符串和消息,算法找到一个划分点并进行部分解密,之后定位准确的划分点完成最终的解密过程并输出结果。该算法使用了 C++ 的标准库。
#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值