https://lovelyunsh.tistory.com/25
[백준] 10158 개미
1. 문제 www.acmicpc.net/problem/10158 10158번: 개미 가로 길이가 w이고 세로 길이가 h인 2차원 격자 공간이 있다. 이 격자는 아래 그림처럼 왼쪽 아래가 (0,0)이고 오른쪽 위가 (w,h)이다. 이 공간 안의 좌표 (
lovelyunsh.tistory.com
자바8로 제출함
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int w = Integer.parseInt(st.nextToken());
int h = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine(), " ");
int p = Integer.parseInt(st.nextToken());
int q = Integer.parseInt(st.nextToken());
int t = Integer.parseInt(br.readLine());
int x = (p+t)%(2*w);
int y = (q+t)%(2*h);
x = w - Math.abs(w-x);
y = h - Math.abs(h-y);
System.out.println(x+" "+y);
}
}
'백준' 카테고리의 다른 글
[백준] 26071 오락실에 간 총총이 [자바] (0) | 2022.12.03 |
---|---|
[백준] 1647 도시 분할 계획 [자바] (0) | 2022.10.12 |
[백준] 18353 병사 배치하기 [자바] (0) | 2022.09.08 |
[백준] 12015 가장 긴 증가하는 부분 수열 2 [자바] (0) | 2022.08.29 |
[백준] 1300 K번째 수 [자바] (0) | 2022.08.29 |