-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomA_1124.cpp
More file actions
60 lines (51 loc) · 1.12 KB
/
comA_1124.cpp
File metadata and controls
60 lines (51 loc) · 1.12 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
int solve(const std::string word) // 2021136089 À̰ü¿ì
{
int cnt{1};
bool preCharHasBlank{true};
if (word.length() == 0)
return 0;
else
{
int i{0};
while (word[i] == ' ')
{
if (i == word.length() - 1)
return 0;
++i;
}
for (int j = i; j < word.length(); ++j)
{
if (word[j] == ' ' && !preCharHasBlank)
{
++cnt;
preCharHasBlank = true;
}
else if (word[j] != ' ')
preCharHasBlank = false;
}
}
return preCharHasBlank ? cnt - 1 : cnt;
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int T;
std::cin >> T;
std::cin.ignore();
std::string word_arr[1000];
int result[1000];
for (int t{0}; t < T; ++t)
{
getline(std::cin, word_arr[t]);
result[t] = solve(word_arr[t]);
}
for (int t{0}; t < T; ++t)
{
std::cout << result[t] << '\n';
}
return 0;
}