Algorithm/BOJ
[BOJ]11721번: 열 개씩 끊어 출력하기(c++)
HBGB
2020. 4. 13. 16:56
https://www.acmicpc.net/problem/11721
11721번: 열 개씩 끊어 출력하기
첫째 줄에 단어가 주어진다. 단어는 알파벳 소문자와 대문자로만 이루어져 있으며, 길이는 100을 넘지 않는다. 길이가 0인 단어는 주어지지 않는다.
www.acmicpc.net
방법1 : 모든 문자를 받아서 저장 후, 10개씩 출력하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#pragma warning(disable : 4996)
#include <stdio.h>
using namespace std;
int main()
{
char input[101];
scanf("%s", input);
for (int i = 0; i < sizeof(input) && input[i] != '\0'; i++)
{
printf("%c", input[i]);
if ((i + 1) % 10 == 0)
{
putchar('\n');
}
}
return 0;
}
Colored by Color Scripter
|
방법2 : 문자를 10개씩 받아서 저장 후 바로 출력하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#pragma warning(disable : 4996)
#include <stdio.h>
using namespace std;
int main()
{
char input[11];
while (scanf("%10s", input) != EOF)
{
printf("%s\n", input);
}
return 0;
}
Colored by Color Scripter
|
scanf("%10s", input) 포맷을 잘 활용하자