코드와이
[BAEKJOON] 10158. 개미 본문
문제링크
10158번: 개미
가로 길이가 w이고 세로 길이가 h인 2차원 격자 공간이 있다. 이 격자는 아래 그림처럼 왼쪽 아래가 (0,0)이고 오른쪽 위가 (w,h)이다. 이 공간 안의 좌표 (p,q)에 개미 한 마리가 놓여있다. 개미는 오
www.acmicpc.net
package acmicpc.Siver2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class 개미 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder sb = new StringBuilder();
int w = Integer.parseInt(st.nextToken());
int h = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int t = Integer.parseInt(br.readLine());
x += t;
y += t;
x %= (2 * w);
y %= (2 * h);
if(x > w) x = 2 * w - x;
if(y > h) y = 2 * h - y;
sb.append(x).append(" ").append(y);
System.out.println(sb);
}
}
'acmicpc' 카테고리의 다른 글
[BAEKJOON] 1929. 소수 구하기 (0) | 2021.03.01 |
---|---|
[BAEKJOON] 2564경비원 (0) | 2021.02.26 |
[BAEKJOON] 10799. 쇠막대기 (0) | 2021.02.26 |
[BAEKJOON] 2669. 직사각형 네개의 합집합의 면적 구하기 (0) | 2021.02.26 |
[BAEKJOON] 2477. 참외밭 (0) | 2021.02.24 |