字符串分割,以及字符串匹配
来源:互联网 发布:me域名多少钱 编辑:程序博客网 时间:2024/06/07 23:37
package cn.jjs.test;
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str=sc.nextLine();
String[] A=str.split(";");
int x=0,y=0;
for(String string:A){
if(string.length() > 0)
{
if(string.charAt(0)=='D' && string.substring(1).matches("[0-9]+"))
x+=Integer.parseInt(string.substring(1));
if(string.charAt(0)=='W' && string.substring(1).matches("[0-9]+"))
y+=Integer.parseInt(string.substring(1));
if(string.charAt(0)=='S' && string.substring(1).matches("[0-9]+"))
y-=Integer.parseInt(string.substring(1));
if(string.charAt(0)=='A' && string.substring(1).matches("[0-9]+"))
x-=Integer.parseInt(string.substring(1));
}
}
System.out.println(x+","+y);
}
sc.close();
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str=sc.nextLine();
String[] A=str.split(";");
int x=0,y=0;
for(String string:A){
if(string.length() > 0)
{
if(string.charAt(0)=='D' && string.substring(1).matches("[0-9]+"))
x+=Integer.parseInt(string.substring(1));
if(string.charAt(0)=='W' && string.substring(1).matches("[0-9]+"))
y+=Integer.parseInt(string.substring(1));
if(string.charAt(0)=='S' && string.substring(1).matches("[0-9]+"))
y-=Integer.parseInt(string.substring(1));
if(string.charAt(0)=='A' && string.substring(1).matches("[0-9]+"))
x-=Integer.parseInt(string.substring(1));
}
}
System.out.println(x+","+y);
}
sc.close();
}
}
0 0
- 字符串分割,以及字符串匹配
- shell下分割字符串以及截取字符串
- Nstring 字符串的截取 匹配字符串 分割字符串
- iOS字符串的截取、匹配、分割
- 数组以及字符串拼接与分割
- OC 数组以及字符串拼接与分割
- c 以及 c++中字符串分割
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- android 实现截取 内容超过屏幕大小的长图
- Spark Hbase读取操作的一些总结与测试
- okHttp post&get请求
- Visual Studio属性配置中使用宏
- out.println()和<%=%>那种输出方式更好?
- 字符串分割,以及字符串匹配
- unsigned long的一点应用
- 为 Tomcat 安装 apr
- 吉布斯采样——原理及matlab实现
- 算法之美--交换排序--冒泡排序
- >>> FilterDispatcher <<< is deprecated! Please use the new filters!
- input核心
- 查询结果集合成一列的sqlserver实现方法stuff
- python强制类型转换(dpkt)