강의

멘토링

커뮤니티

Inflearn Community Q&A

skdyekdtls3886's profile image
skdyekdtls3886

asked

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

55. Train Operation (Application of Stack Data Structure)

맞왜틀

Written on

·

272

0

빨간 세로선 기준으로 왼쪽이 제가 입력한 코드의 결과이고 오른쪽이 강사님의 코드의 결과입니다.

채점을 할 때 강사님꺼는 Success가 뜨는데 제꺼는 Wrong_answer가 뜨네요 ㅠ 뭐가 문제일까요.

 

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <string>

#include <algorithm>

#include <vector>

#include <stack>

 

using namespace std;

 

int main(int argc, char** argv) {

//freopen("input.txt", "rt", stdin);

int n, i = 1, j = 0, start, count = 0;

scanf("%d", &n);

stack<int> s;

char* a = new char[n * 2];

 

while (count < n) {

scanf("%d", &start);

s.push(start);

a[j++] = 'P';

 

while (!s.empty() && s.top() == i) {

s.pop();

a[j++] = 'O';

i++;

}

 

count++;

}

 

if (s.empty()) {

for (i = 0; i < j; i++)

printf("%c", a[i]);

}

else

printf("impossible\n");

delete[] a;

}

 

C++코테 준비 같이 해요!

Answer 1

0

skdyekdtls3886님의 프로필 이미지
skdyekdtls3886
Questioner

시간지나서 빌드하고 다시해보니 제대로 채점되네요! 뭔가 이상한 프로그램 오류가 있었나봅니다!

skdyekdtls3886's profile image
skdyekdtls3886

asked

Ask a question