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 |
Tags
- inflearn
- 제프리리처
- 10026번
- 열혈 tcp/ip 프로그래밍
- HTTP
- Operating System
- redis
- 우아한레디스
- FIFO paging
- n타일링2
- Window-Via-c/c++
- 스프링 핵심 원리
- BOJ
- 스프링 입문
- 이펙티브코틀린
- OS
- C++
- Four Squares
- 열혈 TCP/IP 소켓 프로그래밍
- 운영체제
- 윤성우 저자
- 우아한 테크 세미나
- TCP/IP
- 2475번
- 김영한
- 토마토
- 에러핸들링
- Spring
- Operating System.
- C#
Archives
- Today
- Total
나의 브을로오그으
[c++] 1152번 : 단어의 개수 본문
https://www.acmicpc.net/problem/1152
1152번: 단어의 개수
첫 줄에 영어 대소문자와 공백으로 이루어진 문자열이 주어진다. 이 문자열의 길이는 1,000,000을 넘지 않는다. 단어는 공백 한 개로 구분되며, 공백이 연속해서 나오는 경우는 없다. 또한 문자열
www.acmicpc.net
#include <iostream>
#include <string>
#define TRIM_SIGN " \t\n\r\v\f"
inline std::string& lTrim(std::string& str, const char* drop = TRIM_SIGN)
{
str.erase(0, str.find_first_not_of(drop));
return str;
}
inline std::string& rTrim(std::string& str, const char* drop = TRIM_SIGN)
{
str.erase(str.find_last_not_of(drop) + 1);
return str;
}
inline std::string& Trim(std::string& str, const char* drop = TRIM_SIGN)
{
rTrim(lTrim(str));
return str;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::string str = "";
int nCount = 0;
std::getline(std::cin, str);
Trim(str, " ");
if (str.length() > 0)
{
++nCount;
}
for (int i = 0; i < str.length(); ++i)
{
if (str[i] == ' ')
{
++nCount;
}
}
std::cout << nCount << '\n';
return 0;
}'알고리즘 > BaekJoon' 카테고리의 다른 글
| [c++] 1546번 : 평균 (0) | 2022.03.11 |
|---|---|
| [c++] 1330번 : 두 수 비교하기 (0) | 2022.03.11 |
| [c++] 1008번 : A/B (0) | 2022.03.10 |
| [c++] 1001번 : A-B (0) | 2022.03.10 |
| [c++] 2558 : A+B-2 (0) | 2022.03.09 |