개발자 톡

연습문제 톡 [HSAT 1회 정기 코딩 인증평가 기출] 로봇이 지나간 경로

[HSAT 1회 정기 코딩 인증평가 기출] 로봇이 지나간 경로 반례 부탁드립니다.

등록일
2023-10-04 14:26:53
조회수
381
작성자
won6948


#include 
#include 
#include 
#include 

using namespace std;

string answer;

int dh[4]={0,1,0,-1};
int dw[4]={1,0,-1,0};//동남서북 동쪽기준 시계방향
char dir[4]={'>','v','<','^'};
int starth;
int startw;
char startdir;
int diridx;

char map[26][26];


int h,w;

bool validcheck(int x,int y){
	if(x>0 && y>0 && x<=h && y<=w) return true;
	else return false;

}

void findstart(){
	for(int i =1; i<=h;i++){
		for(int j=1;j<=w;j++){
			if(map[i][j]=='#'){
				int solocheck=0;
				for(int d=0;d<4;d++){
					if(validcheck(dh[d]+i,dw[d]+j) && map[dh[d]+i][dw[d]+j]=='#'){
						solocheck++;
					}
				}
				if(solocheck==1){
					starth=i;
					startw=j;
					startdir=dir[diridx];
					cout<< starth << " " <> h >> w;

	memset(map,'.',sizeof(map));

	for(int i =1; i<=h;i++){
		for(int j=1;j<=w;j++){
			cin >> map[i][j];
		}
	}

	findstart();
	findroute();

	cout << answer;

	return 0;
}

테스트 케이스랑 어느정도는 통과가 되는데 오답의 원인을 모르겠습니다... 반레 부탁드립니다. 

#[hsat_1회_정기_코딩_인증평가_기출]_로봇이_지나간_경로
#c++

이 카테고리의 톡 더보기