인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

유하's profile image
유하

asked

Introduction to Algorithm Problem Solving for IT Employment (with C/C++): Coding Test Preparation

55. Train Operation (Application of Stack Data Structure)

55강 가차운행에서

Written on

·

207

0

코딩테스트에서 이렇게 

system("cls");

cout << "impossible";  imposible 시에 콘솔화면을 지우고 출력해도 되나요 ? 

 (왜냐면 제 코드는 P나 O값을 배열에 넣지 않고 그냥 출력하기 떄문에 

imposible 이더라도  P나O가 출력이 됩니다.

그렇기때문에 지우고 imposible 출력하도록 하였는데요)

#include <iostream>
#include <stack>
#include <vector>
#include<algorithm>
using namespace std;

int main(void) {
	int i = 0, arr[4] = { 2,3,1,4 }, search = 1;
	//cin >> n;
	//cin >> m;
	stack<int> s;
	

	for(i=0;i<4;i++){
		s.push(arr[i]);
		cout << 'P';
		
		while (!s.empty()) {
			
			if (s.top() == search) {
				search++;
				s.pop();
				cout << 'O';
			}
			else break;
		}
	}
	if (!s.empty()) {
		system("cls");
		cout << "impossible";
	}
}
C++코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

저도 잘 모르겠습니다.ㅠㅠ

제가 드린 채점폴더에서 채점해보세요. 정상채점이 되면 다른 시스템에서도 채점될 확률이 높습니다.

하지만 확실하지 않는 방법은 사용하지 않는게 좋을 것 같습니다.

유하's profile image
유하

asked

Ask a question