sentence = input()
n=1
sentence = sentence.strip()
sentence = sentence.rjust(1, '1')
if sentence[-1]!='1':
for i in range(len(sentence)):
if sentence[i] == ' ':
n+=1
print(n)
else:
print(0)
문제: https://www.acmicpc.net/problem/1152
1152번: 단어의 개수
첫 줄에 영어 대소문자와 공백으로 이루어진 문자열이 주어진다. 이 문자열의 길이는 1,000,000을 넘지 않는다. 단어는 공백 한 개로 구분되며, 공백이 연속해서 나오는 경우는 없다. 또한 문자열
www.acmicpc.net
'Baekjoon > python' 카테고리의 다른 글
[백준 5622번] 다이얼 (0) | 2023.02.08 |
---|---|
[백준 2908번] 상수 (0) | 2023.02.03 |
[백준 1157번] 단어 공부 (0) | 2023.02.03 |
[백준 2675번] 문자열 반복 (0) | 2023.01.26 |
[백준 10809번] 알파벳 찾기 (1) | 2023.01.26 |