티스토리 뷰

PS/백준

1152번 단어의 개수

unside 2019. 6. 22. 17:07

백준 1152번

문제 사이트 :
https://www.acmicpc.net/problem/1152

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

#define Max 1000002
int Array[Max];
int main(void) {
	int index = 0;
	while (1) {
		char ch;
		if (scanf("%c", &ch) == -1) {
			break;
		}
		if (ch == '\n' || ch == '\0' ||ch == EOF)
			break;
		if (index == 0 && ch == ' ') {
			continue;
		}
		Array[index] = ch;
		index++;
	}
	if (Array[index - 1] == '\n') {
		Array[index - 1] = '\0';
		index--;
	}
	if (Array[index-1] == ' ') {
		Array[index-1] = '\0';
		index--;
	}
	int number = 0;
	for (int i = 0; i < index; i++) {
		if (Array[i] == ' ') {
			number++;
		}
	}
	if (index != 0) {
		number++;
	}
	printf("%d", number);
	return 0;
}

'PS > 백준' 카테고리의 다른 글

1316번 그룹 단어 체커  (0) 2019.06.22
1157번 단어 공부  (0) 2019.06.22
1110번 더하기 사이클  (0) 2019.06.22
1065번 한 수  (0) 2019.06.22
4344번 평균은 넘겠지  (0) 2019.06.18
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/11   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
글 보관함