알고리즘
[C++] 백준 11721번 열 개씩 끊어 출력하기
J3SUNG
2019. 3. 5. 14:02
728x90
string에 입력을 받은 후 substr 함수로 10글자씩 잘라서 출력합니다.
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char * argv[])
{
string s;
cin >> s;
int ten = s.size() / 10;
int won = s.size() % 10;
for (int i = 1; i <= ten; i++) {
cout << s.substr(10 * (i - 1), 10) << "\n";
}
if (won != 0) {
cout << s.substr(ten * 10, won) << "\n";
}
return 0;
}