More actions
imported>Unknown No edit summary |
(Repair batch-0003 pages from live compare) |
||
| Line 15: | Line 15: | ||
if (length < 3) | if (length < 3) | ||
return false; | return false; | ||
if (str | if (str[0] != 'D' && str[0] != 'E') | ||
return false; | return false; | ||
if (str | if (str[1] != 'F') | ||
return false; | return false; | ||
temp = str.find_first_not_of('F', 2); | temp = str.find_first_not_of('F', 2); | ||
if (temp == -1) | if (temp == -1) | ||
return false; | return false; | ||
if (temp == length - 1 && str | if (temp == length - 1 && str[temp] == 'G') | ||
return true; | return true; | ||
else | else | ||
| Line 33: | Line 33: | ||
if (length < 2) | if (length < 2) | ||
return false; | return false; | ||
if (str | if (str[0] != 'A') | ||
return false; | return false; | ||
if (length == 2 && str | if (length == 2 && str[1] == 'H') | ||
return true; | return true; | ||
if (length != 2 && str | if (length != 2 && str[length - 1] == 'C') | ||
{ | { | ||
if (str | if (str[1] == 'B') | ||
return isSlimp(str.substr(2, length - 3)); | return isSlimp(str.substr(2, length - 3)); | ||
else | else | ||
| Line 84: | Line 84: | ||
---- | ---- | ||
[[Slurpys/곽세환]] | [[Slurpys/곽세환]] | ||
Latest revision as of 00:29, 27 March 2026
소감
- 통과O
- 예전같으면 일일이 만들었을 함수들을 그냥 string 함수로 해결
소스
//384
#include <iostream>
using namespace std;
#include <string>
bool isSlump(string str)
{
int length = str.length();
int temp = -1;
if (length < 3)
return false;
if (str[0] != 'D' && str[0] != 'E')
return false;
if (str[1] != 'F')
return false;
temp = str.find_first_not_of('F', 2);
if (temp == -1)
return false;
if (temp == length - 1 && str[temp] == 'G')
return true;
else
return isSlump(str.substr(temp, length - temp));
}
bool isSlimp(string str)
{
int length = str.length();
if (length < 2)
return false;
if (str[0] != 'A')
return false;
if (length == 2 && str[1] == 'H')
return true;
if (length != 2 && str[length - 1] == 'C')
{
if (str[1] == 'B')
return isSlimp(str.substr(2, length - 3));
else
return isSlump(str.substr(1, length - 2));
}
return false;
}
bool isSlurpy(string str)
{
int i, j, temp = -1; // temp는 Slimp의 마지막 문자 위치
int length = str.length();
temp = str.find_last_of('C');
if (temp == -1)
temp = str.find_last_of('H');
// Slimp와 Slump로 분리해서 검사
if (temp != -1 && isSlimp(str.substr(0, temp + 1)) && isSlump(str.substr(temp + 1, length - temp - 1)))
return true;
else
return false;
}
int main()
{
int numberOfCase;
cin >> numberOfCase;
int testCase, i, j;
cout << "SLURPYS OUTPUT" << endl;
for (testCase = 0; testCase < numberOfCase; testCase++)
{
string str;
cin >> str;
if (isSlurpy(str))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
cout << "END OF OUTPUT" << endl;
return 0;
}