Algorithm, Data structure/Solved Algorithmic Problem

BAEKJOON 2675 - Repeating Characters

JaykayChoi 2016. 11. 20. 13:22

출처: https://www.acmicpc.net/problem/2675


문제

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$%*+-./:

입력

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 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.

출력

For each data set there is one line of output. It contains the data set number, N, followed by a single space which is then followed by the new string T, which is made of each character in S repeated R times.

예제 입력 

2
3 ABC
5 /HTP

예제 출력 

AAABBBCCC
/////HHHHHTTTTTPPPPP

힌트

출처

ACM-ICPC Regionals North America Greater New York Region 2011 Greater New York Programming Contest A번

  • 문제를 번역한 사람: baekjoon
  • 잘못된 데이터를 찾은 사람: pichulia


아마 우리 그네누나도 코딩을 배웠다면 풀 수 있을 정도로 아무 생각없이 풀 수 있는 문제네요.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <fstream>
#include <iostream>
#include <cstring>
#include <climits>
#include <algorithm>
 
#include <string>
using namespace std;
 
 
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int repeat;
        cin >> repeat;
        string str;
        cin >> str;
        for (int j = 0; j < str.length(); j++)
        {
            for (int k = 0; k < repeat; k++)
            {
                cout << str[j];
            }
        }
        cout << endl;
    }
    return 0;
}
 
 
cs