arrow_forward همه ارسال‌ها

جزئیات ارسال کد#997

verified
وضعیت داوری نهایی: پذیرفته شد
terminal
زبان برنامه‌نویسی: Java
schedule
ارسال‌کننده و زمان:
khashayar moeinfar (۵ ماه پیش)
descriptionMain.java ۳۶ خط • ۷۷۶ بایت
1import java.util.*;
2
3class Main {
4
5 public static void main(String[] args) {
6
7 Scanner sc = new Scanner(System.in);
8
9 int n = sc.nextInt();
10 int p = sc.nextInt();
11
12 int[] position = new int[]{
13 sc.nextInt(),
14 sc.nextInt()
15 };
16 sc.nextLine();
17
18 String s = sc.nextLine();
19
20 int[] direction = new int[]{
21 p * ((s.contains("S") ? 1 : 0) - (s.contains("N") ? 1 : 0)),
22 p * ((s.contains("E") ? 1 : 0) - (s.contains("W") ? 1 : 0))
23 };
24
25
26 for (int i = 0; i < 2; i++) {
27 position[i] = (((position[i] + direction[i]) % n)+n)%n;
28 }
29
30 System.out.println(position[0]+" "+position[1]);
31
32
33 }
34
35
36}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8