😈 알고리즘/💻 백준
💻 1152번 문제 : 단어의 개수
Buᐢ༝ᐢy
2022. 10. 7. 17:53
1152번: 단어의 개수


#include <iostream>
#include <string>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int count = 0;
int check = false;
string inputString;
getline(cin, inputString);
int stringLength = inputString.length();
if (stringLength == 0)
{
cout << count;
}
else
{
for (int i = 0; i < stringLength; i++)
{
if (inputString[i] != ' ' && check == false)
{
check = true;
count++;
}
else if (inputString[i] == ' ')
{
check = false;
}
}
cout << count;
}
}
메모리 (KB) | 시간 (ms) | 코드 길이 (B) |
3680 | 8 | 555 |
Uploaded by N2T