首页 > ACM题库 > HDU-杭电 > HDU 4236-Repeating Characters[解题报告]HOJ
2015
05-23

HDU 4236-Repeating Characters[解题报告]HOJ

Repeating Characters

问题描述 :

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 repaeated 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:
  
0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z $ % * + – . / :

输入:

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 a single ling 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.

输出:

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 a single ling 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.

样例输入:

2
1 3 ABC
2 5 /HTP

样例输出:

1 AAABBBCCC
2 /////HHHHHTTTTTTPPPPP

#include<iostream>
#include<string>
using namespace std;
char ch[25];

int main()
{
	int n, i, j;
	scanf("%d", &n);
	while(n--)
	{
		int a, b;
		scanf("%d%d%*c%s", &a, &b, ch);
		printf("%d ", a);
		for(i = 0; ch[i] != '\0'; i++)
		{
			for(j = 0; j < b; j++)
				printf("%c", ch[i]);
		}
		printf("\n");
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/asure__cpp/article/details/8580953