2019个人训练赛-F - Two Small Strings

You are given two strings ss and tt both of length 22 and both consisting only of characters 'a', 'b' and 'c'.

Possible examples of strings ss and tt : "ab", "ca", "bb".

You have to find a string resres consisting of 3n3n characters, nn characters should be 'a', nn characters should be 'b' and nn characters should be 'c' and ss and tt should not occur in resres as substrings.

A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".

If there are multiple answers, you can print any of them.

Input

The first line of the input contains one integer nn (1n1051≤n≤105 ) — the number of characters 'a', 'b' and 'c' in the resulting string.

The second line of the input contains one string ss of length 22 consisting of characters 'a', 'b' and 'c'.

The third line of the input contains one string tt of length 22 consisting of characters 'a', 'b' and 'c'.

Output

If it is impossible to find the suitable string, print "NO" on the first line.

Otherwise print "YES" on the first line and string resres on the second line. resres should consist of 3n3n characters, nn characters should be 'a', nn characters should be 'b' and nn characters should be 'c' and ss and tt should not occur in resres as substrings.

If there are multiple answers, you can print any of them.

Examples

Input
2
ab
bc
Output
YES
acbbac
Input
3
aa
bc
Output
YES
cacbacbab
Input
1
cb
ac
Output
YES
abc
学会了使用迭代器来遍历vector,棒棒哒
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

vector<string> arr;
int n;
string abc="abc",c;

int main(){
    string s,t;
    cin>>n>>s>>t;
    
    do{
        string cur;
        for(int i=0;i<n;i++)
            cur+=abc;
        arr.push_back(cur);
        arr.push_back(string(n,abc[0])+string(n,abc[1])+string(n,abc[2]));
    }while(next_permutation(abc.begin(), abc.end()));
    
    for(std::vector<string>::iterator it=arr.begin();it!=arr.end();it++){
        string::size_type position,position1;
        c=*it;
        position =c.find(s);
        position1=c.find(t);
        if(position==c.npos&&position1==c.npos){
            cout<<"YES"<<endl;
            cout<<c<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

 

 

转载于:https://www.cnblogs.com/gbtj/p/11488680.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值