YJ/C++

[백준/BOJ/C++] 17010번 Time to Decompress

Team DAON 2021. 10. 22. 14:32

[문제]

You and your friend have come up with a way to send messages back and forth.

Your friend can encode a message to you by writing down a positive integer N and a symbol. You can decode that message by writing out that symbol N times in a row on one line.

Given a message that your friend has encoded, decode it.

 

[입력]

The first line of input contains L, the number of lines in the message.

The next L lines each contain one positive integer less than 80, followed by one space, followed by a (non-space) character.

 

[출력]

The output should be L lines long. Each line should contain the decoding of the corresponding line of the input. Specifically, if line i+1 of the input contained N x, then line i of the output should contain just the character x printed N times.

 

[Source Code]

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int test;
	cin >> test;
	int *count = new int[test];
	char *character = new char[test];

	for(int i = 0; i < test; i++){
		int inputcount;
		char inputcharacter;
		cin >> inputcount >> inputcharacter;
		count[i] = inputcount;
		character[i] = inputcharacter;
	}

	for(int i = 0; i < test; i++){
		for(int j = 0; j < count[i]; j++){
			cout << character[i];
		}
		cout << "\n";
	}
}

[결과 화면]