-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5550.cpp
90 lines (86 loc) · 1.46 KB
/
5550.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 5550. 나는 개구리로소이다
// 2019.07.07
#include<iostream>
#include<string>
using namespace std;
int main()
{
int test_case;
int T;
cin >> T;
string croak = "croak";
for (test_case = 1; test_case <= T; ++test_case)
{
string s;
cin >> s;
int pos = 0;
int ans = 0;
bool flag = true;
// 개구리를 찾았는지 찾지 못했는지
bool find = false;
//
bool ansFlag = true;
string tmp = "";
while (flag)
{
tmp = s;
find = false;
for (int i = 0; i < s.size(); i++)
{
// 개구리 울음소리 검사. 검사된건 '0'으로 바꿈
if (s[i] == croak[pos])
{
s[i] = '0';
pos++;
// 끝까지 도달하면 개구리를 찾음
if (pos == 5)
{
find = true;
pos = 0;
}
}
// 최종 검사
if (i == s.size() - 1)
{
// 개구리를 찾음
if (find)
{
// 울음소리가 끝나지 않았다면 개구리가 아님
if (pos != 0)
{
ansFlag = false;
break;
}
}
// 개구리를 찾지 못함
else
{
s = tmp;
flag = false;
}
}
}
if (find)
{
ans++;
}
}
for (int i = 0; i < s.size(); i++)
{
// 울음소리 흔적이 남아있다면 개구리 울음소리가 아님.
if (s[i] != '0')
{
ansFlag = false;
}
}
if (ansFlag)
{
cout << "#" << test_case << " " << ans << endl;
}
else
{
cout << "#" << test_case << " -1" << endl;
}
}
return 0;
}