개발자 톡

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

어디가 문제인건지 잘 모르겠습니다!

등록일
2024-02-02 19:52:48
조회수
260
작성자
yoobin11
#include<iostream>
#include<vector>


using namespace std;

int main(int argc, char** argv)
{
   int H=0;
    int W=0;
    cin>>H>>W;
    vector<vector<char>> map(W,vector<char>(H,0));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>map[i][j];
        }
    }

    pair<int,int> A;
    pair<char,char> dir;
    dir.first = '0'; 
    dir.second = '0'; 
    string ans;
    int k=0;
    for(int i=0;i<W;i++){
        for(int j=0;j<H;j++){
            if(map[i][j]=='#'&&A.first==0){
                    A.first=i+1;
                    A.second=j+1;
                    if(map[i][j+1]=='#'){
                        dir.first='>';
                        dir.second='>';
                    }
                    else if(map[i+1][j]=='#'){
                        dir.first='v';
                        dir.second='v';
                    }
                k=10;
                break;
            }
            }
        if(k==10){
            break;
        }
    }
    
    int i=A.first-1;
    int j=A.second-1;
    
    while(1){
        int count=0;
                if(map[i][j]=='#'&&map[i][j+1]=='#'){
                        if(dir.second=='>'){
                            ans.push_back('A');
                            map[i][j+1]='0';
                            j+=2;
                            continue;
                        }    
                        else if(dir.second=='v'){
                            ans.push_back('L');
                            ans.push_back('A');
                            dir.second='>';
                            map[i][j+1]='0';
                            j+=2;
                            continue;
                        }
                        else if(dir.second=='^'){
                            ans.push_back('R');
                            ans.push_back('A');
                            dir.second='>';
                            map[i][j+1]='0';
                            j+=2;
                            continue;
                        }
                }
                else if(map[i][j]=='#'&&map[i+1][j]=='#'){
                        if(dir.second=='v'){
                            ans.push_back('A');
                            map[i+1][j]='0';
                            i=i+2;
                            continue;
                        }
                        else if(dir.second=='<'){
                            ans.push_back('L');
                            ans.push_back('A');
                            dir.second='v';
                            map[i+1][j]='0';
                            i+=2;
                            continue;
                        }
                        else if(dir.second=='>'){
                            ans.push_back('R');
                            ans.push_back('A');
                            dir.second='v';
                            map[i+1][j]='0';
                            i+=2;
                            continue;
                        }
                }
                else if(map[i][j]=='#'&&map[i][j-1]=='#'){
                        if(dir.second=='<'){
                            map[i][j-1]='0';
                            ans.push_back('A');
                            j-=2;
                            continue;
                        }
                        else if(dir.second=='^'){
                            map[i][j-1]='0';
                            ans.push_back('L');
                            ans.push_back('A');
                            dir.second='<';
                            j-=2;
                            continue;
                        }
                        else if(dir.second=='v'){
                            map[i][j-1]='0';
                            ans.push_back('R');
                            ans.push_back('A');
                            dir.second='<';
                            j-=2;
                            continue;
                        }
                }
                else if(map[i][j]=='#'&&map[i-1][j]=='#'){
                        if(dir.second=='^'){
                            map[i-1][j]='0';
                            ans.push_back('A');
                            i-=2;
                            continue;
                        }
                        else if(dir.second=='>'){
                            map[i-1][j]='0';
                            ans.push_back('L');
                            ans.push_back('A');
                            dir.second='^';
                            i-=2;
                            continue;
                        }
                        else if(dir.second=='<'){
                            map[i-1][j]='0';
                            ans.push_back('R');
                            ans.push_back('A');
                            dir.second='^';
                            i-=2;
                            continue;
                        }
                }
        if(count==0){
            break;
        }
                
    }
    cout<<A.first<<" "<<A.second<<endl<<dir.first<<endl<<ans;
   return 0;
}


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

이 카테고리의 톡 더보기