Google Kickstart 2019 C轮 Wiggle Walk

原题链接在这:

2019C轮A题:Wiggle Walk

我的代码:

import java.util.*;
    public class Solution {   	
      public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
        for (int i = 1; i <= t; i++) {
          int N=in.nextInt();
          int R=in.nextInt();
          int C=in.nextInt();
          int SR=in.nextInt();
          int SC=in.nextInt();
          String ins=in.next();
          char[] ins_array=new char[N];
          for(int j=0;j<N;j++) {
        	  ins_array[j]=ins.charAt(j);
          }
          boolean[][] arrived=new boolean[R+1][C+1];
          arrived[SR][SC]=true;
          for(int j=0;j<N;j++) {
        	  if(ins_array[j]=='N') {//R--
        		  while(arrived[SR-1][SC]==true) {
        			  SR--;
        		  }  
        		  if(R>1) {
        			  SR--;
        			  arrived[SR][SC]=true;
        		  }       		  
        	  }
        	  else if(ins_array[j]=='S') {//R++
        		  while(arrived[SR+1][SC]==true) {
        			  SR++;
        		  }      
        		  if(SR<R) {
        			  SR++;
        			  arrived[SR][SC]=true;
        		  }       		         		  
        	  }else if(ins_array[j]=='E') {//C++
        		  while(arrived[SR][SC+1]==true) {
        			  SC++;
        			  arrived[SR][SC]=true;
        		  }  
        		  if(SC<C) {
        			  SC++;
        			  arrived[SR][SC]=true; 
        		  }   		 
        	  }else if(ins_array[j]=='W') {//C--
        		  while(arrived[SR][SC-1]==true) {
        			  SC--;
        			  arrived[SR][SC]=true;
        		  } 
        		  if(SC>1) {
        			  SC--;
        			  arrived[SR][SC]=true;  
        		  }     		  
        	  }      		  
          }

          System.out.println("Case #" + i + ": "+SR+" "+SC);
        }
        in.close();
      }
    }

可以过测试样例,但是上测试数据集会出现RE(运行错误),暂且还没有找到错误原因。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值