5.23 VJ F - Construct the String

#include<bits/stdc++.h>
#define ll long long
using namespace std;
/*
此题与Vj B - Phoenix and Beauty类似,只是把数字换成了字符。根据题意,b的大小即为周期数,找到周期数再循环输出即可。
*/
int main()
{
    int t,n,a,b;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        cin>>n>>a>>b;
        string s;//存放一个周期的字符
        char ch='a';
        for(int j=0; j<b; j++)
        {
            s+=ch;
            ch++;//一个周期的字符数为b
        }
        for(int j=0;j<n/b;j++)//根据n的大小输出n/b个周期
        {
            cout<<s;
        }
        for(int j=0;j<n%b;j++)//输出剩下的不足一个周期的字符
        {
            cout<<s.at(j);
        }
        cout<<endl;
    }
}

猜你喜欢

转载自www.cnblogs.com/SyrupWRLD999/p/12944748.html
vj
今日推荐