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
- 정처기
- Xilinx
- FPGA
- UNIX
- SQL
- chip2chip
- Bus
- 자격증
- Vivado
- Backjoon
- 백준
- HDLBits
- axi
- Beakjoon
- 코딩테스트
- verilog HDL
- 리눅스
- 정보처리기사
- java
- hdl
- baekjoon
- amba
- C++
- verilog
- AMBA BUS
- linux
- vitis
- Zynq
- boj
- 실기
Archives
- Today
- Total
Hueestory
[1152] 단어의 개수 (C++) 본문
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string str; getline(cin, str);
int result = 1;
for (int i = 0; i < str.length(); i++) {
if (str[i] == ' ')
result++;
}
if (str[0] == ' ')
result--;
if (str[str.length() - 1] == ' ')
result--;
cout << result << endl;
return 0;
}
1. 공백이 등장하면 단어의 개수 +1
if (str[0] == ' ')
result--;
if (str[str.length() - 1] == ' ')
result--;
2. 문자열의 첫 부분과 마지막 부분이 공백이면 result값 -1, 위 부분을 빼먹어서 틀렸던 문제
'PS(중단) > BOJ' 카테고리의 다른 글
[2438] 별 찍기 - 1 (C++) (0) | 2024.04.25 |
---|---|
[1330] 두 수 비교하기 (C++) (0) | 2024.04.25 |
[1008] A/B (C++) (0) | 2024.04.25 |
[1001] A-B (C++) (0) | 2024.04.25 |
[1000] A+B (C++) (0) | 2024.04.25 |
Comments