코딩 테스트/알고리즘 풀이

[백준 - 2562] 문자열 반복

김띠띵 2022. 8. 10. 01:04
#include <iostream>
#include <string>
using namespace std;

int main()
{
	ios::sync_with_stdio(0), cin.tie(0);
	int N; cin >> N;

	int R;
	string str;
	for (int i = 0; i < N; ++i)
	{
		cin >> R;
		cin >> str;
		for (char c : str)
		{
			cout << string(R, c);
		}
		cout << "\n";
	}
	return 0;
}

||사용 기법

  • string 생성자
  • string을 이용한 ranged for loop

||새로 알게 된것

  • string 생성자에서 원하는 개수와 원하는 문자로 생성 

string (원하는 개수, 원하는 문자) 로 생성하는걸 처음알았다.

ex) string(5,'A') == "AAAAA" 가 생성된다.