회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
3425번 게시판 반례 다 통과하는데 틀린 부분 알려주실수있나요 도와주세요
3425번 - 고스택
lototheve
1년 전
0
게시판 반례 다 맞게 나오는데 어디서 틀린건지 도저히 모르겠습니다.
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> using namespace std; long long N; long long M; long long K; vector<string> v; vector<long long> n; bool input() { string com; long long num; while (1) { cin >> com; if (com == "NUM") { cin >> num; v.push_back(com); n.push_back(num); } else if (com == "END") { v.push_back(com); break; } else if (com == "QUIT") { return false; } else { v.push_back(com); } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long input_num = 0; long long inp = 0; string quit; stack<long long> st; while (1) { if (!input()) { break; } cin >> input_num; for (long long i = 0; i < input_num; i++) { cin >> inp; st.push(inp); long long k = 0; for (long long j = 0; j < v.size(); j++) { if (v[j] == "NUM") { st.push(n[k]); k++; } if (v[j] == "POP") { if (st.empty()) { cout << "ERROR" << endl; return 0; } st.pop(); } if (v[j] == "INV") { if (st.empty()) { cout << "ERROR" << endl; return 0; } st.top() = -st.top(); } if (v[j] == "DUP") { if (st.empty()) { cout << "ERROR" << endl; return 0; } st.push(st.top()); } if (v[j] == "SWP") { if (st.size() < 2) { cout << "ERROR" << endl; return 0; } long long temp1 = st.top(); st.pop(); long long temp2 = st.top(); st.pop(); st.push(temp1); st.push(temp2); } if (v[j] == "ADD") { if (st.size() < 2) { cout << "ERROR" << endl; return 0; } long long temp = st.top(); st.pop(); st.top() = st.top() + temp; } if (v[j] == "SUB") { if (st.size() < 2) { cout << "ERROR" << endl; return 0; } long long temp = st.top(); st.pop(); st.top() = st.top() - temp; } if (v[j] == "MUL") { if (st.size() < 2) { cout << "ERROR" << endl; return 0; } long long temp = st.top(); st.pop(); st.top() = st.top() * temp; } if (v[j] == "DIV") { if (st.size() < 2) { cout << "ERROR" << endl; return 0; } long long temp2 = st.top(); st.pop(); long long temp1 = st.top(); st.pop(); if (temp2 == 0) { cout << "ERROR" << endl; return 0; } if (temp1 < 0 && temp2 > 0) { temp1 = -temp1; temp1 = -temp1 / temp2; } else if (temp1 > 0 && temp2 < 0) { temp2 = -temp2; temp1 = -temp1 / temp2; } else if(temp1 < 0 && temp2 < 0){ temp2 = -temp2; temp1 = -temp1; temp1 = temp1 / temp2; } else{ temp1 = temp1 / temp2; } st.push(temp1); } if (v[j] == "MOD") { if (st.size() < 2) { cout << "ERROR" << endl; return 0; } long long temp2 = st.top(); st.pop(); long long temp1 = st.top(); st.pop(); if (temp2 == 0) { cout << "ERROR" << endl; return 0; } if (temp1 < 0 && temp2 > 0) { temp1 = -temp1; temp1 = -temp1 % temp2; } else if (temp1 > 0 && temp2 < 0) { temp2 = -temp2; temp1 = temp1 % temp2; } else if (temp1 < 0 && temp2 < 0) { temp2 = -temp2; temp1 = -temp1; temp1 = -temp1 % temp2; } else { temp1 = temp1 % temp2; } st.push(temp1); } if (v[j] == "END") { break; } } if (st.empty()) { cout << "ERROR" << endl; return 0; } long long result = st.top(); st.pop(); if (st.empty() && (result <= 1000000000 && result >= -1000000000)) { cout << result << endl; } else { cout << "ERROR" << endl; } } while (!st.empty()) { st.pop(); } v.clear(); n.clear(); cout << endl; } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
lototheve 1년 전
게시판 반례 다 맞게 나오는데 어디서 틀린건지 도저히 모르겠습니다.