Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 31 |
Tags
- 그래프
- 문제풀이
- 오에스
- 컴퓨터공학과
- 개발
- 너비우선탐색
- Operating System
- vector
- OS
- cs
- c++
- 브루트포스
- 오퍼레이팅시스템
- 정석
- 자료구조
- 코딩
- 백준
- 코테
- 컴공
- bfs
- 스택
- 구현
- coding
- 정석학술정보관
- 알고리즘
- 북리뷰
- Computer science
- Stack
- 컴공과
- DP
Archives
- Today
- Total
Little Jay
[C++] 백준 1152번 단어의 개수 본문
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
getline(cin, s);
int count = 0;
if (s.empty())
{
cout << "0";
return 0;
}
count = 1;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == ' ')
count++;
}
if (s[0] == ' ')
count--;
if (s[s.length() - 1] == ' ')
count--;
cout << count;
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 11050번 이항 계수1 (0) | 2021.03.21 |
|---|---|
| [C++] 백준 10773번 제로 (0) | 2021.03.21 |
| [C++] 백준 10809번 알파벳 찾기 (0) | 2021.03.15 |
| [C++] 백준 2577번 숫자의 개수 (0) | 2021.03.14 |
| [C++] 백준 10814번 나이순 정렬 (0) | 2021.03.11 |
Comments