题解 | #坐标移动#

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

import java.util.Scanner; import java.util.regex.Pattern;  public class Main{   public static void main(String[] args)  {  Scanner scanner = new Scanner(System.in);  String s = scanner.nextLine();  String[] split = s.split(";");   //正则表达式  String ruleString1 = "[ADWS][0-9]{1,2}";  Pattern pattern = Pattern.compile(ruleString1);   int x  = 0, y = 0;  for (String s1 : split) {  if (pattern.matcher(s1).matches()) {  int distance = Integer.valueOf(s1.substring(1));  char direction = s1.charAt(0);  if ('A' == direction) {  x -= distance;  } else if ('D' ==direction) {  x += distance;  } else  if ('W' == direction) {  y += distance;  } else if ('S' == direction) {  y -= distance;  }    }  }   System.out.println(x+","+y);   }  }
全部评论

相关推荐

点赞 评论 收藏
分享
双非坐过牢:非佬,可以啊10.28笔试,11.06评估11.11,11.12两面,11.19oc➕offer
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务