Two Small Strings

题目链接:http://codeforces.com/contest/1213/problem/E

题意

s和t都是由字母a b c中的一种或两种字符 组成的长度为2的字符串
找到一个字符串 其中a b c三个字母各出现n次,并且s和t不是其连续子序列

思路

如果a,b自己的两个字符都不一样,直接全排列abc,一定会有一种情况满足条件,然后输出aaaabbbbcccc这种格式
否则的话也是全排列,然后输出abcabcabc这种格式

#include <bits/stdc++.h>
const int N=1e6+5;
using namespace std;
#define LL long long
int n,m,k;
void slove(string a,string b){
	string s="abc";
	do{
		if((s[1]==b[1]&&s[0]==b[0])||(s[2]==b[1]&&s[1]==b[0])||(n>1&&s[2]==b[0]&&s[0]==b[1]));
		else
			{
				char ch[4];
				ch[0]=s[0];ch[1]=s[1];ch[2]=s[2];ch[3]=0;
				for(int i=1;i<=n;i++)
					printf("%s",ch);
				return ;
			}
	}while(next_permutation(s.begin(),s.end()));
}
int main(){
	cin>>n;
	string a,b;
	cin>>a>>b;
	puts("YES");
	if(a[0]==a[1]||b[0]==b[1]){
		if(b[0]==b[1])
			slove(b,a);
		else
			slove(a,b);
	}else{
		string s="abc";
		do{
			if((s[1]==a[1]&&s[0]==a[0])||(s[2]==a[1]&&s[1]==a[0])||(s[1]==b[1]&&s[0]==b[0])||(s[2]==b[1]&&s[1]==b[0]));
			else
				{
					for(int i=0;i<3;i++)
						for(int j=1;j<=n;j++)
							printf("%c",s[i]);
					return 0;
				}
		}while(next_permutation(s.begin(),s.end()));
	}
    return 0;
}

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值