其他分享
首页 > 其他分享> > 18 年湘潭邀请赛

18 年湘潭邀请赛

作者:互联网

String Transformation
hud 6282
字符c 把两个字符串分割,遍历被分割的每一个区间
ba < — > ab;
统计每个区间 a ,b的奇偶性,一致就可以转化

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#define endl '\n'
#define epc 1e-14
using namespace std;
typedef long long ll;
const int N = 1e3 + 9;
string s ,t;
vector <pair<int,int> > v1, v2;
int main()
{
	while(cin >> s >> t)
	{
		v1.clear(),v2.clear();
		int a = 0, b = 0;
		int lt = t.length(), ls = s.length();
		for(int i = 0 ; i < lt; ++i) 
		{
			if(t[i] == 'a') ++a;
			else if(t[i] == 'b') ++b;
			else if(t[i] == 'c')
			{
				v2.push_back(make_pair(a, b));
				a=b=0;
			}
			if(i == lt - 1) v2.push_back(make_pair(a, b));// 打个补丁
		}
		 
		a = b = 0;
		for(int i = 0 ; i < ls; ++i) 
		{
			if(s[i] == 'a') ++a;
			else if(s[i] == 'b') ++b;
			else if(s[i] == 'c' )
			{
				v1.push_back(make_pair(a, b));
				a=b=0;
			}
			if(i == ls-1)v1.push_back(make_pair(a, b));
		}
		if(v1.size() == v2.size())
		{
			bool f = 1;
			for(int i = 0; i < v1.size(); ++i)
			{
				if(v1[i].first%2 != v2[i].first%2 || v1[i].second%2 != v2[i].second%2){
					f=0;break;
				}
			}
			if(f) cout << "Yes\n";
			else cout << "No\n";
		}
		else cout << "No\n";
	}
	return 0;
}

/*
cabab
ababc

cba
abc
*/

标签:湘潭,int,18,++,back,v1,v2,include,邀请赛
来源: https://blog.csdn.net/cosx_/article/details/116378278