본문 바로가기
Programming/Algorithm

백준 문자열 입력받기

by OKOK 2018. 1. 25.

#include <iostream>

#include <string>


using namespace std;


int T;

int R;

string word;


void problem_in() {

cin >> R;

cin >> word;

}


void solve() {


string word_new = "";


for (int i = 0; i < word.length(); i++) {

for (int j = 0; j < R; j++) {

word_new += word[i];

}

}


cout << word_new << endl;

}


int main(void) {

cin >> T;

for (int i = 0; i < T; i++) {

problem_in();

solve();

}


return 0;


c++ 에서 문자열 입력받기 위해서, string 을 사용합니다. 그럼 간단하게 한번에 받을 수도 있고, 받은 후에 문자하나씩 접근할 수 있습니다. 그리고 배열의 크기를 먼저 설정해주지 않아도 된다는 점이 가장 좋습니다. 오케이요. 그리고 나서 하나씩 접근해서 처리가 가능합니다. 그리고 새로운 것에 더할때도 하나씩 접근해서 더할 수 있어서 좋습니다. 오케이요.