Advertisement
nmh07000

Main

Mar 2nd, 2024 (edited)
1,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.*;
  2. public class Main{
  3.     public static void main(String[] args) {
  4.         Scanner scan = new Scanner(System.in);
  5.         String s = scan.next();
  6.         int[] arr = new int[4];
  7.         arr[0] = s.indexOf('N');
  8.         arr[1] = s.indexOf('S');  
  9.         arr[2] = s.indexOf('E');
  10.         arr[3] = s.indexOf('W');
  11.        
  12.         if((arr[0] >= 0 && arr[1] >= 0 && arr[2] >= 0 && arr[3] >= 0) ||
  13.             (arr[0] >= 0 && arr[1] >= 0 && arr[2] == -1 && arr[3] == -1) ||
  14.             (arr[0] == -1 && arr[1] == -1 && arr[2] >= 0 && arr[3] >= 0)) {
  15.             System.out.println("Yes");
  16.         }
  17.         else {
  18.             System.out.println("No");
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement