아래 문제에서 error를 출력할때 continue를 입력했을경우, break 대신에 error가 무기한 출력이되는 문제가 발생한다.
BAPC 2012 문제의 테스트 케이스를 분석해보고 나서야 깨달았다............. 주의해야 겠다
BAPC 2012 문제의 테스트 케이스를 분석해보고 나서야 깨달았다............. 주의해야 겠다
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <string> | |
#include <deque> | |
using namespace std; | |
int main() | |
{ | |
deque<int> deq; | |
int T; | |
cin >> T; | |
string op; | |
int ary_size, num; | |
for (int i = 0; i < T; i++) { | |
cin >> op; | |
cin >> ary_size; | |
char ch; | |
bool reverse = false; | |
cin >> ch; | |
deq.clear(); | |
for (int j = 0; j < ary_size; j++) { | |
cin >> num; | |
cin >> ch; | |
deq.push_back(num); | |
} | |
if (ary_size == 0) | |
cin >> ch; | |
bool print = true; | |
for (int j = 0; j < op.size(); j++) { | |
if (op[j] == 'R') | |
{ | |
reverse = !reverse; | |
} | |
else if (op[j] == 'D') { | |
if (deq.empty()) | |
{ | |
cout << "error" << endl; | |
print = false; | |
break; | |
} | |
if (reverse) | |
deq.pop_back(); | |
else | |
deq.pop_front(); | |
} | |
} | |
if (print == false) | |
continue; | |
cout << "["; | |
if (reverse) { | |
for (int i = 0; i < deq.size()/2; i++) { | |
int temp = deq[i]; | |
deq[i] = deq[deq.size() - i - 1]; | |
deq[deq.size() - i - 1] = temp; | |
} | |
} | |
for (int j = 0; j < deq.size(); j++) { | |
if (j == deq.size() - 1) { | |
cout << deq[j]; | |
} | |
else | |
cout << deq[j] << ","; | |
} | |
cout << "]" << endl; | |
} | |
} |
댓글
댓글 쓰기