zoukankan      html  css  js  c++  java
  • Codeforces Round #527 (Div. 3) A. Uniform String

    A. Uniform String

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    You are given two integers nn and kk.

    Your task is to construct such a string ss of length nn that for each ii from 11 to kk there is at least one ii-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minimal frequency of some letter (the frequency of a letter is the number of occurrences of this letter in a string). If there are several possible answers, you can print any.

    You have to answer tt independent queries.

    Input

    The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of queries.

    The next tt lines are contain queries, one per line. The ii-th line contains two integers nini and kiki (1≤ni≤100,1≤ki≤min(ni,26)1≤ni≤100,1≤ki≤min(ni,26)) — the length of the string in the ii-th query and the number of characters in the ii-th query.

    Output

    Print tt lines. In the ii-th line print the answer to the ii-th query: any string sisi satisfying the conditions in the problem statement with constraints from the ii-th query.

    Example

    input

    Copy

    3
    7 3
    4 4
    6 2
    

    output

    Copy

    cbcacab
    abcd
    baabab
    

    Note

    In the first example query the maximum possible minimal frequency is 22, it can be easily seen that the better answer doesn't exist. Other examples of correct answers: "cbcabba", "ccbbaaa" (any permutation of given answers is also correct).

    In the second example query any permutation of first four letters is acceptable (the maximum minimal frequency is 11).

    In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is 33).

    #include<iostream>
    using namespace std;
    
    int main()
    {
    	int n,m,j,k,i,T,sum2,sum3;
    	cin>>T;
    	while (T--)
    	{
    		cin>>n>>k;
    		if (n%k==0)
    		{
    			int sum1 = n/k;
    			for (i='a';i<='a'+k-1;i++)
    			{
    				for (j=0;j<sum1;j++)
    				printf("%c",i);
    			}
    			printf("
    ");
    		}
    		
    		else
    		{
    			sum2 = n/k,sum3 = sum2+n%k;
    			for (i='a';i<='a'+k-2;i++)
    			{
    				for (j=0;j<sum2;j++)
    				printf("%c",i);
    			}
    			for (j=0;j<sum3;j++)
    			printf("%c",'a'+k-1);
    			printf("
    ");
    		}
    		
    		
    		
    		
    	}
    	
    	return 0;
    }
  • 相关阅读:
    Python3 日期与时间戳相互转换
    PHP 二维数组排序保持键名不变
    C# Command命令(行为型模式)+队列 实现事务,带异步命令重试机制和生命周期
    领域驱动系列五模型驱动设计的构造块
    领域驱动系列四之模型驱动
    领域驱动系列三
    领域驱动系列二策略模式的应用
    领域驱动系列一基本概念介绍
    Redis学习系列七分布式锁
    Redis学习系列六ZSet(有序列表)及Redis数据结构的过期
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451328.html
Copyright © 2011-2022 走看看