Algorithm/BackJoon
11721번: 열 개씩 끊어 출력하기
꼬부기가우는소리
2023. 6. 27. 09:09
728x90
- 문제 사이트: https://www.acmicpc.net/problem/11721
11721번: 열 개씩 끊어 출력하기
첫째 줄에 단어가 주어진다. 단어는 알파벳 소문자와 대문자로만 이루어져 있으며, 길이는 100을 넘지 않는다. 길이가 0인 단어는 주어지지 않는다.
www.acmicpc.net
입력 받은 전체 문자열을 10문자씩 끊어서 출력하는 문제이다.
string의 substr 함수를 이용해 문제를 풀어주었다.
#include <iostream>
using namespace std;
int main()
{
string str;
cin >> str;
for (int i = 0; i < str.length(); i += 10)
cout << str.substr(i, 10) << "\n";
return 0;
}
- 메모리: 2024 KB
- 시간: 0 ms
- 코드 길이: 192 B
아래와 같이 10문자씩 입력받는 방법도 존재한다.
#include <cstdio>
int main()
{
char str[11];
while(scanf("%10s", str) != EOF)
printf("%s\n", str);
return 0;
}
- 메모리: 1112 KB
- 시간: 0 ms
- 코드 길이: 119 B
728x90