게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
C++ Runtime Error 좀 도와주세요...
게시물ID : programmer_4365짧은주소 복사하기
작성자 : sleepig
추천 : 0
조회수 : 322회
댓글수 : 1개
등록시간 : 2014/07/05 02:00:15
#include <iostream>
#include <string>
using namespace std; 

int M = 0, N = 0;
char matrix[250][250];  

//C는 입력 받은 color, B는 (x,y)의 기존 color
void fill(int X, int Y, char C, char B) {
matrix[Y][X] = C;
if( Y > 0 && matrix[Y-1][X] == B ) 
fill(X, Y-1, C, B); 
if( X > 0 && matrix[Y][X-1] == B ) 
fill(X-1, Y, C, B);
if( Y+1 < N && matrix[Y+1][X] == B ) 
fill(X, Y+1, C, B);
if( X+1 < M && matrix[Y][X+1] == B ) 
fill(X+1, Y, C, B);
}//end of fill()

int main(int argc, const char *argv[]) {
string name; 
char command = 0;
char color; 
int x1, y1, x2, y2; 
int tmp;

while(command != 'X') {
cin >> command; 

switch(command) { 
case 'I' :
cin >> M >> N;
case 'C' :
for (int i = 0; i < N; i++) 
for (int j = 0; j < M; j++) 
matrix[i][j] = 'O';
break;
case 'L' :
cin >> x1 >> y1 >> color; 
matrix[y1-1][x1-1] = color;
break;
case 'V' :
cin >> x1 >> y1 >> y2 >> color; 
if(y1 > y2) {
tmp = y1; 
y1 = y2; 
y2 = tmp;
}//end of if
for (int i = y1-1; i < y2; i++) 
matrix[i][x1-1] = color;
break;
case 'H' :
cin >> x1 >> x2 >> y1 >> color; 
if(x1 > x2) {
tmp = x1; 
x1 = x2; 
x2 = tmp;
}//end of if
for (int i = x1-1; i < x2; i++) 
matrix[y1-1][i] = color;
break;
case 'K' :
cin >> x1 >> y1 >> x2 >> y2 >> color;
for (int i = y1-1; i < y2; i++) {
for (int j = x1-1; j < x2; j++) {
matrix[i][j] = color;
}//end of for
}//end of for 
break;
case 'F' :
cin >> x1 >> y1 >> color; 
fill(x1-1, y1-1, color, matrix[y1-1][x1-1]);
break;
case 'S' :
cin >> name; 
cout << name << endl; 
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cout << matrix[i][j];
}//end of for 
cout << endl;
}//end of for 
break;
}//end of switch
}//end of while
return 0;
}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------//

윗 부분이 전체 코드입니다. 이걸 리눅스에서 돌리면 아무 문제 없이 잘 돌아가는데, UVa Online Judge에서 코드를 돌려서 확인해보려고 하니

//C는 입력 받은 color, B는 (x,y)의 기존 color
void fill(int X, int Y, char C, char B) {
matrix[Y][X] = C; 
if( Y > 0 && matrix[Y-1][X] == B ) 
fill(X, Y-1, C, B); 
if( X > 0 && matrix[Y][X-1] == B ) 
fill(X-1, Y, C, B);
if( Y+1 < N && matrix[Y+1][X] == B ) 
fill(X, Y+1, C, B);
if( X+1 < M && matrix[Y][X+1] == B ) 
fill(X+1, Y, C, B);
}//end of fill()

이 함수 부분에서 런타임 에러가 발생하네요. 이것저것 주석달면서 하다보니 이 함수 내용 자체를 주석을 달면 코드가 돌아가서 오답이라고 나오는데, 

이 부분에서 왜 런타임 에러가 발생하는지를 모르겠네요. 


//------------------------------------------------------------------------------------------------------------------------------------------------------------------//

추가적인 문제 조건은,   

1 <= M, N <= 250 이고, 

If as a command there will be a character different from I, C, L, V, H, K, F, S, X, the editor should ignore the whole line and pass to the next command.

In case of other errors the program behaviour is unpredictable.


입니다. 

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호