회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
예제는 맞는데 틀렸다고 나오네요 ㅠㅠ알려주세요
14499번 - 주사위 굴리기
dudwhd93
7년 전
0
고수분들 도와주세요!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
package samsung_practice; import java.util.Scanner; public class Main { static int currentC; static int currentR; static int N,M; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] map; int[] dice; int[] command; int K; int pointC,pointR; N = sc.nextInt(); M = sc.nextInt(); pointR = sc.nextInt(); pointC = sc.nextInt(); K = sc.nextInt(); map = new int[N][M]; dice = new int[7]; command = new int[K]; for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ map[i][j] = sc.nextInt(); } } for(int i=0;i<K;i++){ command[i] = sc.nextInt(); } ////////////////입력 끝///////////////////// currentR = pointR; currentC = pointC; for(int i=0;i<K;i++){ int direction = command[i]; move(map,dice,direction); } } static void move(int[][] map,int[] dice,int direction){ int temp; if((currentR==0 && direction==3) || (currentR==N-1 && direction==4)|| (currentC==0 && direction==2)|| (currentC==M-1 && direction==1)){ return; }//맵을 벗어나는 경우 처리 switch(direction){ case 1://동쪽 temp = dice[3]; dice[3]=dice[1]; dice[1]=dice[4]; dice[4]=dice[6]; dice[6]=temp; currentC++; break; case 2: //서쪽 temp = dice[1]; dice[1]=dice[3]; dice[3]=dice[6]; dice[6]=dice[4]; dice[4]=temp; currentC--; break; case 3://북쪽 temp = dice[2]; dice[2]=dice[1]; dice[1]=dice[5]; dice[5]=dice[6]; dice[6]=temp; currentR--; break; case 4://남쪽 temp = dice[5]; dice[5]=dice[1]; dice[1]=dice[2]; dice[2]=dice[6]; dice[6]=temp; currentR++; break; } //주사위 상태 변환 완료 && 맵 상 현재위치 변경 완료 //dice[6] 은 주사위 밑면의 수 //dice[1] 은 주사위 윗면의 수 if(map[currentR][currentC]==0){ map[currentR][currentC]=dice[6]; }else{ dice[6]=map[currentR][currentC]; map[currentR][currentC]=0; } //System.out.println("현재위치 = "+currentR+","+currentC); //주사위 윗면의 수 출력 //System.out.println("윗면:"+dice[1]+"밑면:"+dice[6]); System.out.println(dice[1]); } }
댓글을 작성하려면
로그인
해야 합니다.
dudwhd93 7년 전
고수분들 도와주세요!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!