当前位置: 移动技术网 > 移动技术>移动开发>IOS > Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)

Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)

2020年07月27日  | 移动技术网移动技术  | 我要评论
题目链接题意:给你一个长度为n的数组,让你构造出n+1个字符串,使得s[i]和s[i+1]之间的最长前缀和等于a[i]。思路:首先构造一个长度为60字母全为a的字符串,然后按照输入的a[i]遍历字符串,到达需要改变的位置时,如果该位置是a则变成b,后续有b的情况是b则变成a即可。代码:#include<bits/stdc++.h>using namespace std;#define int long long#define IOS ios::sync_with_stdio(f

题目链接

题意:

给你一个长度为n的数组,让你构造出n+1个字符串,使得s[i]和s[i+1]之间的最长前缀和等于a[i]。

思路:

首先构造一个长度为60字母全为a的字符串,然后按照输入的a[i]遍历字符串,到达需要改变的位置时,如果该位置是a则变成b,后续有b的情况是b则变成a即可。

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=1e5+7;
const int M=4e5+8;
const double eps=1e-8;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926;
signed main()
{
	IOS;
	int t;
	cin>>t;
	while(t--)
	{
		int n,a[105];
		char s[205];
		for(int i=0;i<60;i++)
        {
            s[i]='a';
        }
		cin>>n;
		for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(int i=0;i<=n;i++)
        {
            if(i>0)
            {
                for(int j=0;;j++)
                {
                    if(j==a[i])
                    {
                        if(s[j]=='a')
                        {
                            s[j]='b';
                        }
                        else
                        {
                            s[j]='a';
                        }
                        break;
                    }
                }
            }
            for(int j=0;j<60;j++)
            {
                cout<<s[j];
            }
            cout<<endl;
        }
	}
	return 0;
}

本文地址:https://blog.csdn.net/ACkingdom/article/details/107574683

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网