일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- spotify
- 파이썬
- 스포티파이
- Spring JPA
- SECS-II
- Computer Science
- CS
- Gem
- 비트겟
- python
- 자바
- modern c++
- programmers
- c
- SECS/GEM
- regression
- Spring
- Baekjoon
- Spotify Api
- SECS
- spring boot
- SW Expert Academy
- SWEA
- 프로그래머스
- 회원가입
- 회귀
- java
- 백준
- Bitget
- C++
Archives
- Today
- Total
비버놀로지
[SWEA SW Expert Academy] 4013 특이한 자석 본문
728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
4개의 톱니바퀴를 시계방향 또는 반시계방향으로 돌려 주변의 톱니바퀴에 영향을 미치는 문제이다.
3번째 톱니바퀴를 돌릴 경우, 2번째와 4번째의 톱니바퀴와 맞닿은 부분의 자성이 같을 경우, 2번째 4번째의 톱니바퀴도 회전시킨다.
다를 경우, 회전시키지 않는다.
package com.ssafy.study;
import java.util.LinkedList;
import java.util.Scanner;
public class SEWA_4013_특이한자석 {
private static LinkedList<Integer> first; //첫번째 톱니바퀴
private static LinkedList<Integer> second; //두번째 톱니바퀴
private static LinkedList<Integer> third; //세번째 톱니바퀴
private static LinkedList<Integer> forth; //넷번째 톱니바퀴
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
int s = 8;
for (int t = 1; t <= T; t++) {
int K = sc.nextInt();
first = new LinkedList<Integer>();
second = new LinkedList<Integer>();
third = new LinkedList<Integer>();
forth = new LinkedList<Integer>();
for (int i = 0; i < s; i++) {
first.add(sc.nextInt());
}
for (int i = 0; i < s; i++) {
second.add(sc.nextInt());
}
for (int i = 0; i < s; i++) {
third.add(sc.nextInt());
}
for (int i = 0; i < s; i++) {
forth.add(sc.nextInt());
}
for (int k = 0; k < K; k++) {
int arr[] = new int[5];
int number = sc.nextInt(); //회전시킬 톱니바퀴
int type = sc.nextInt(); // 1일경우 시계방향, -1일 경우 반시계방향
switch (number) {
case 1: //첫번째 톱니바퀴 회전
arr[1] = type;
type *= -1;
if (first.get(2) != second.get(6)) {
arr[2] = type;
type *= -1;
if (second.get(2) != third.get(6)) {
arr[3] = type;
type *= -1;
if (third.get(2) != forth.get(6)) {
arr[4] = type;
}
}
}
break;
case 2: //두번째 톱니바퀴 회전
arr[2] = type;
type *= -1;
if (second.get(6) != first.get(2)) {
arr[1] = type;
}
if (second.get(2) != third.get(6)) {
arr[3] = type;
type *= -1;
if (third.get(2) != forth.get(6)) {
arr[4] = type;
type *= -1;
}
}
break;
case 3: //세번째 톱니바퀴 회전
arr[3] = type;
type *= -1;
if (third.get(2) != forth.get(6)) {
arr[4] = type;
}
if (third.get(6) != second.get(2)) {
arr[2] = type;
type *= -1;
if (second.get(6) != first.get(2)) {
arr[1] = type;
type *= -1;
}
}
break;
case 4: //네번째 톱니바퀴 회전
arr[4] = type;
type *= -1;
if (forth.get(6) != third.get(2)) {
arr[3] = type;
type *= -1;
if (third.get(6) != second.get(2)) {
arr[2] = type;
type *= -1;
if (second.get(6) != first.get(2)) {
arr[1] = type;
}
}
}
break;
}
for (int i = 1; i <= 4; i++) { //arr에 저장되어 있는 회전방향을 이용해서 회전시키기
if (arr[i] != 0) {
spin(i, arr[i]);
}
}
}
int result = 0;
result += first.get(0) * 1;
result += second.get(0) * 2;
result += third.get(0) * 4;
result += forth.get(0) * 8;
System.out.println("#" + t + " " + result);
}
}
private static void spin(int i, int j) {
switch (i) {
case 1:
if (j == -1) {
first.add(first.poll());
} else {
first.addFirst(first.pollLast());
}
break;
case 2:
if (j == -1) {
second.add(second.poll());
} else {
second.addFirst(second.pollLast());
}
break;
case 3:
if (j == -1) {
third.add(third.poll());
} else {
third.addFirst(third.pollLast());
}
break;
case 4:
if (j == -1) {
forth.add(forth.poll());
} else {
forth.addFirst(forth.pollLast());
}
break;
}
}
}
728x90
'ALGORITM > JAVA' 카테고리의 다른 글
[SWEA SW Expert Academy] 5658 보물상자 비밀번호 (0) | 2020.12.02 |
---|---|
[SWEA SW Expert Academy] 1249 보급로 (0) | 2020.12.01 |
[BAEKJOON 백준] 17406 배열돌리기 4 (0) | 2020.08.31 |
[BAEKJOON 백준] 1992 쿼드트리 (0) | 2020.08.30 |
[BAEKJOON 백준] 15686 치킨 배달 (0) | 2020.08.30 |
Comments