今日头条 8.25 双生词

题目
#include <iostream>
#include <map>
#include <string>

using namespace std;

int shaungshengci()
{
	map<string, int> se;
	int ret = 0;
	int num = 0;
	cin >> num;
	for (int j = 0; j < num; j++)
	{

		string a;
		cin >> a;
		int len = a.size();
		
		string c;
		c.assign(a.rbegin(), a.rend());
		c += c;
		a += a;
		string::iterator ie = c.begin();
		string::iterator it = a.begin();
		for (; a.end() - it>len && ret != 1; it++,ie++)
		{
			string b(it, it + len);
			pair<map<string,int>::iterator,bool> pa = se.insert(pair<string, int>(b, j));
			if (pa.second == false)
			{
				if (pa.first->second != j)
				{
					ret = 1;
					break;
				}
			}
			string d(ie, ie + len);

			pair<map<string, int>::iterator,bool> pb = se.insert(pair<string, int>(d, -1));
			if (pb.second == false)
			{
				if (pb.first->second != j)
				{
					ret = 1;
					break;
				}
			}
		}
	}
	return ret;
}

int main()
{
	int size = 0;
	cin >> size;
	for (int i = 0; i < size; i++)
	{
		int ret = shaungshengci();
		if (ret == 1)
		{
			cout << "Yeah" << endl;
		}
		else
		{
			cout << "Sad";
		}
	}
	return 0;
}

考完后才想到的    不知道有没有错误   没办法验证,,,,,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值