华为 17

<span style="font-size:24px;">package NiukeBrush;
//开发一个坐标计算工具, A表示向左移动,D表示向右移动,W表示向上移动,
//S表示向下移动。从(0,0)点开始移动
//,从输入字符串里面读取一些坐标,并将最终输入结果输出到输出文件里面。

import java.util.Scanner;

public class Huawei17 {

	public static void main(String[] args) {
	
//		{
//			String st=sc.nextLine();
//			String[] str=st.split(";");
//			int n=sc.nextInt();
//			StringBuilder sb=new StringBuilder(st);
//			//统计A,B,C,D变量
//			int a=0; 
//			int a1=0;
//			int b=0;
//			int b1=0;
//			int c=0;
//			int c1=0;
//			int d=0;
//			int d1=0;
//			
//			//当sb.length的长度等于1的时候
//			for(int i=0;i<str.length;i++)
//			{
//			 while(str[i].length()==3){
//            //	如果字符索引的第一个等于A、B、C、D
//			if((st.charAt(0)=='A'))	
//			{
//				a++;
//				
//			}
//			else if(st.charAt(0)=='B')
//             {
//            	 b++;
//             }
//			else if(st.charAt(0)=='C')
//			{
//				c++;
//			}
//			else if(st.charAt(0)=='D')
//			{
//				d++;
//			}
//			
		//键盘输入
		Scanner sc=new Scanner(System.in);
		//定义横坐标、纵坐标
		int x=0;
		int y=0;
	
		String st=sc.nextLine();
		String[] str=st.split(";");
		while(sc.hasNext()){
			//遍历循环
			for(int i=0;i<str.length;i++)
			{
			//判断这个字符串的长度,不能大于三位
		  while(str[i].length()<=3)
		  {
			  if(str[i].charAt(0)=='A'&& str[i].substring(1).matches("[0-9]+"))
			  {
				  x-=Integer.parseInt(str[i].substring(1));
			  }
			  if(str[i].charAt(0)=='D'&& str[i].substring(1).matches("[0-9]+"))
			  {
				  x+=Integer.parseInt(str[i].substring(1));
			  }
			  if(str[i].charAt(0)=='W'&& str[i].substring(1).matches("[0-9]+"))
			  {
				  y+=Integer.parseInt(str[i].substring(1));
			  }
			  if(str[i].charAt(0)=='S'&& str[i].substring(1).matches("[0-9]+"))
			  {
				  y-=Integer.parseInt(str[i].substring(1));
			  }
		  }
			
			
			}
		}
		sc.close();
		System.out.println("("+x+","+y+"0");
	}

}
</span>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值