1-M 좋은단어 반례를 찾아보고싶습니다!
해결됨
10주완성 C++ 코딩테스트 | 알고리즘 코딩테스트
강의를 듣기전에 제가 먼저 문제를 해결해보고, 강사님의 풀이방법이랑 비교하는식으로 학습중에 있습니다. 1-M 좋은단어 푸는 도중 백준의 반례 예시 BABBAB ABBABB ABBBBA AAAAABBAAAAA 이경우를 다 해봤는데도 안되서, 강사님 풀이를 보기 전에 제힘으로 해결해보고자 하는데 반례 찾기에 도움을 여쭐수 있을까요? 아래는 코드입니다 #include<iostream> #include<algorithm> #include<string> #include<map> #include<vector> using namespace std; int main() { ios::ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int count = 0; bool check = true; for (int i = 0; i < n; i++) { string temp; cin >> temp; int cnt2=0; check = true; if (temp.length() % 2 == 1) continue; while (check && temp.length()) { if (temp[0] == 'A') { if (temp[temp.length()-1] == 'A') { temp.erase(temp.length() - 1, 1); temp.erase(0, 1); } else { int loc = temp.find('A', 1); if (loc % 2 == 0 or loc == -1) check = false; else { temp.erase(loc, 1); temp.erase(0, 1); } } } else { int end = temp.length() - 1; if (temp[temp.length()-1] == 'B') { temp.erase(temp.length() - 1, 1); temp.erase(0, 1); } else { int loc = temp.find('B', 1); if (loc % 2 == 0 or loc == -1) check = false; else { temp.erase(loc, 1); temp.erase(0, 1); } } } } if(check) count++; } cout << count; system("pause"); return 0; }
- 1-M
- 좋은단어
- C++
- 코테 준비 같이 해요!





