회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
5430번 문제 틀렸습니다가 자꾸뜨네요
5430번 - AC
chanmin4
5년 전
0
예외케이스를 못잡은거같은데 고수분들 도와주십쇼 ㅠㅠ
#include<string> #include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<stack> #include<queue> #include<deque> #include<sstream> using namespace std; int main() { cin.tie(NULL); ios::sync_with_stdio(false);//printf 와 연결끊음 주의 int test = 0; cin >> test; int first = 0, last = 0, n = 0, num = 0; int count = 0; int position = 0; int tempo = 0; deque<int>arr; string a = ""; string hello = ""; for (int i = 0; i < test; i++) { count = 0; position = 0; while (!arr.empty()) { arr.pop_front(); } cin >> a; cin >> n; cin >> hello; hello = hello.substr(1, hello.length() - 2); if (hello == "") { cout << "error" << "\n"; break; } while (1) { tempo = hello.find(",", position); if (tempo == -1) { num = stoi(hello.substr(position,hello.size()-position)); arr.push_back(num); break; } num = stoi(hello.substr(position,tempo-position)); position = tempo+1; arr.push_back(num); } first = 0; last = arr.size() - 1; for (int k = 0; k < a.length(); k++) { if (a[k] == 'R') { swap(first, last); count++; } else if (a[k] == 'D') { if (count % 2 == 1) { if (first<last) { break; } first--; } else if (count % 2 == 0) { if(first>last){ break; } first++; } } } if (count % 2 == 1) { if (first < last) { cout << "error" << "\n"; } else { cout << "["; for (int l = first; l >= last; l--) { cout << arr.at(l); if (l != last)cout << ","; } cout << "]\n"; } } else if (count % 2 == 0) { if (first > last) { cout << "error" << "\n"; } else { cout << "["; for (int l = first; l <= last; l++) { cout << arr.at(l); if (l != last)cout << ","; } cout << "]\n"; } } } }
댓글을 작성하려면
로그인
해야 합니다.
chanmin4 5년 전
예외케이스를 못잡은거같은데 고수분들 도와주십쇼 ㅠㅠ