2020-05-22 — 习题训练二-F

F - Construct the String

题意:给定n,a,b,求长度为n,每a个字母含有b个不同的字母的字符串.

解题思路:创建长度为b,前a个字母不同的字符串循环输出即可.

ac代码:

#include<iostream>
using namespace std;
char s[2005];
int main(){
  int t,i,n,a,b;
  cin>>t;
  while(t--){
    cin>>n>>a>>b;
    for(i=0;i<b;i++){
      s[i]=char(i+'A'+32);
    }
    for(i=b;i<a;i++){
      s[i]=s[b-1];
    }
    for(i=0;i<n;i++){
      cout<<s[i%a];
    }
    cout<<endl;
  }
  return 0;
}

 

原文地址:https://www.cnblogs.com/nanan/p/12945843.html