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;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 9498번 시험 성적 (0) | 2019.03.05 |
---|---|
[C++] 백준 15552번 빠른 A+B (0) | 2019.03.05 |
[C++] 백준 11720번 숫자의 합 (0) | 2019.03.05 |
[C++] 백준 8393번 합 (0) | 2019.03.05 |
[C++] 백준 1924번 2007년 (0) | 2019.03.05 |