您的位置:首页 > 其它

Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现 A--A Repeating Characters

2015-04-08 08:36 381 查看

Description

For this problem,you will write a program that takes a string of characters,S,and creates a new string of characters,T,with each character repeated R times.That is,R copies of the first character of S,followed by R copies of the second character of S,and
so on.Valid characters for S are the QR

Code “alphanumeric” characters:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ$%*+-. /:

Input

The first line of input contains a single integer P,(1<=P<=1000),which is the number of data sets that follow. Each data set is single line of input consisting of the data set number N,followed by a space,followed by the repeat count R,(1<=R<=8),followed
by a space ,followed by the string S.The length of string S will always be at least one and no more than 20 characters.All the characters will be from the set of characters shown above.

Output

For each data set there is one line of output. It contains the data set number,

N, followed by a single apace which is then followed by the new string T,which is made of each character in S repeated R times.

Sample Input

2
1 3 ABC
2 5 /HTP

Sample Output

1 AAABBBCCC
2 /////HHHHHTTTTTPPPPP

HINT

AC代码:

#include <iostream>
#include <cstring>
using namespace std;
void fun(string s,char output[],int num){
    int i,count=0,j,m;
    for(i=0;i<(m=s.length());i++){
        j=0;
        while(j<num){
            output[count++]=s[i];
            j++;
        }
    }
    i=0;
    while(i<count)
                cout<<output[i++];
    cout<<'\12';
}
int main(){
    int n,i,num,a;
    string s;
    char output[1000];
    cin>>n;
    i=0;
    while(i<n){
        cin>>a;
        cin>>num;
        cin>>s;
        cout<<a<<" ";
        fun(s,output,num);
        i++;
    }
    return 0;
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐