zoukankan      html  css  js  c++  java
  • B. Construct the String (字符串+思维)

    B. Construct the String
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given three positive integers nn, aa and bb. You have to construct a string ss of length nn consisting of lowercase Latin letters such that each substring of length aa has exactly bb distinct letters. It is guaranteed that the answer exists.

    You have to answer tt independent test cases.

    Recall that the substring s[lr]s[l…r] is the string sl,sl+1,,srsl,sl+1,…,sr and its length is rl+1r−l+1. In this problem you are only interested in substrings of length aa.

    Input

    The first line of the input contains one integer tt (1t20001≤t≤2000) — the number of test cases. Then tt test cases follow.

    The only line of a test case contains three space-separated integers nn, aa and bb (1an2000,1bmin(26,a)1≤a≤n≤2000,1≤b≤min(26,a)), where nn is the length of the required string, aa is the length of a substring and bb is the required number of distinct letters in each substring of length aa.

    It is guaranteed that the sum of nn over all test cases does not exceed 20002000 (n2000∑n≤2000).

    Output

    For each test case, print the answer — such a string ss of length nn consisting of lowercase Latin letters that each substring of length aa has exactly bb distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.

    Example
    input
    Copy
    4
    7 5 3
    6 1 1
    6 6 1
    5 2 2
    
    output
    Copy
    tleelte
    qwerty
    vvvvvv
    abcde
    
    Note

    In the first test case of the example, consider all the substrings of length 55:

    • "tleel": it contains 33 distinct (unique) letters,
    • "leelt": it contains 33 distinct (unique) letters,
    • "eelte": it contains 33 distinct (unique) letters.
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 #define scanf scanf_s
     6 
     7 int T;
     8 int n, a, b;
     9 int main() {
    10     scanf("%d", &T);
    11     while (T--) {
    12         scanf("%d%d%d", &n, &a, &b);
    13         char s[10001];
    14         for (int i = 0; i < n; i++) {
    15             s[i] = 'a' + i % b;
    16         }
    17         s[n] = '';
    18         printf("%s
    ", s);
    19     }
    20 
    21     return 0;
    22 }
  • 相关阅读:
    [Golang学习笔记] 06 程序实体3 类型断言和类型转换
    [Golang学习笔记] 05 程序实体2 作用域访问权限和变量重声明
    [Golang学习笔记] 04 程序实体1 变量声明
    [Golang学习笔记] 03 库源码文件
    virgo-tomcat-server的生产环境线上配置与管理
    virgo-tomcat-server最大并发连接数的修改
    linux系统下kvm虚拟机的安装
    关于virgo-tomcat-server-3.6.0.RELEASE配置文件修改说明
    关于在Linux下apache-maven的安装
    H3C系列之三层交换机文件管理
  • 原文地址:https://www.cnblogs.com/sineagle/p/14476697.html
Copyright © 2011-2022 走看看