package com.zhangle.practise;
import java.util.Scanner;
public class Robert {
/**
* @param args
*/
public static void main(String[] args) {
// 默认不转向就是向上走
//定义地图,每次比较距离重新实例化
//可能不需要二维数组,定义x,y假想坐标原点
int x=0,y=0;
Scanner scanner=new Scanner(System.in);
int num=scanner.nextInt();
String[] array=new String[num];
Scanner scanner2=new Scanner(System.in);
for (int i = 0; i < array.length; i++) {
array[i]=scanner2.next();
}
System.out.println();
String direction="";
String scale="";
String[] ds=null;
String[] ss=null;
for (int i = 0; i < array.length; i++) {
char[] row=array[i].toCharArray();
if (isDirection(row[0])) {
if (row.length>1&&!isDirection(row[1])) {
direction=row[0]+",";
}
else {
direction=row[0]+"";
}
for (int
j = 1; j < row.length; j++) {
if (isDirection(row[j])) {
direction+=row[j];
if (j<row.length-1&&!isDirection(row[j+1])) {
direction+=",";
}
continue;
}
else {
scale+=row[j];
if (j<row.length-1&&isDirection(row[j+1])) {
scale+=",";
}
continue;
}
}
}
else {
if (row.length>1&&isDirection(row[1])) {
scale=row[0]+",";
}
else {
scale=row[0]+"";
}
for (int j = 1; j < row.length; j++) {
if (isDirection(row[j])) {
direction+=row[j];
if (j<row.length-1&&!isDirection(row[j-1])) {
direction+=",";
}
continue;
}
else {
scale+=row[j];
if (j<row.length-1&&isDirection(row[j-1])) {
scale+=",";
}
continue;
}
}
}
ds=direction.split(",");
if (scale.endsWith(",")) {
scale.substring(0, scale.length()-1);
}
ss=scale.split(",");
int a=x,b=y;
String e="";
if (isDirection(row[0])) {
for (int j = 0; j < ss.length; j++) {
e+=ds[j];
int f=calculateDirection(e);
switch (f) {
case 0: y+=Integer.parseInt(ss[j].toString());
break;
case 1:x+=Integer.parseInt(ss[j].toString());
break;
case 2: y-=Integer.parseInt(ss[j].toString());
break;
case 3:x-=Integer.parseInt(ss[j].toString());
break;
}
}
}
else {
y+=Integer.parseInt(ss[0].toString());
for (int j = 0; j < ds.length; j++) {
e+=ds[j];
int f=calculateDirection(e);
if (j<ss.length-1) {
switch (f) {
case 0: y+=Integer.parseInt(ss[j+1].toString());
break;
case 1:x+=Integer.parseInt(ss[j+1].toString());
break;
case 2: y-=Integer.parseInt(ss[j+1].toString());
break;
case 3:x-=Integer.parseInt(ss[j+1].toString());
break;
}
}
}
}
System.out.println(Math.sqrt((x-a)*(x-a)+(y-b)*(y-b)));
}
}
/**
* 判断是数字还是方向字符
* @param ch
* @return
*/
public static boolean isDirection(char ch) {
if (ch>=48&&ch<=57) {
return false;
}
else {
return true;
}
}
/**
* 这里计算多个方向符在一起到底是什么方向,都共有90度角,所以这里以4代表360度
* @param string
* @return
*/
public static int calculateDirection(String string) {
int angle=0;
char[] chs=string.toCharArray();
for (int i = 0; i < chs.length; i++) {
if (chs[i]=='L') {
angle-=1;
}
else {
angle+=1;
}
}
//因为-1向四取余是-1而不是3
return (angle+100)%4;//加了100后,0,1,2,3对应的方向是上右下左
}
}
import java.util.Scanner;
public class Robert {
/**
* @param args
*/
public static void main(String[] args) {
// 默认不转向就是向上走
//定义地图,每次比较距离重新实例化
//可能不需要二维数组,定义x,y假想坐标原点
int x=0,y=0;
Scanner scanner=new Scanner(System.in);
int num=scanner.nextInt();
String[] array=new String[num];
Scanner scanner2=new Scanner(System.in);
for (int i = 0; i < array.length; i++) {
array[i]=scanner2.next();
}
System.out.println();
String direction="";
String scale="";
String[] ds=null;
String[] ss=null;
for (int i = 0; i < array.length; i++) {
char[] row=array[i].toCharArray();
if (isDirection(row[0])) {
if (row.length>1&&!isDirection(row[1])) {
direction=row[0]+",";
}
else {
direction=row[0]+"";
}
for (int
j = 1; j < row.length; j++) {
if (isDirection(row[j])) {
direction+=row[j];
if (j<row.length-1&&!isDirection(row[j+1])) {
direction+=",";
}
continue;
}
else {
scale+=row[j];
if (j<row.length-1&&isDirection(row[j+1])) {
scale+=",";
}
continue;
}
}
}
else {
if (row.length>1&&isDirection(row[1])) {
scale=row[0]+",";
}
else {
scale=row[0]+"";
}
for (int j = 1; j < row.length; j++) {
if (isDirection(row[j])) {
direction+=row[j];
if (j<row.length-1&&!isDirection(row[j-1])) {
direction+=",";
}
continue;
}
else {
scale+=row[j];
if (j<row.length-1&&isDirection(row[j-1])) {
scale+=",";
}
continue;
}
}
}
ds=direction.split(",");
if (scale.endsWith(",")) {
scale.substring(0, scale.length()-1);
}
ss=scale.split(",");
int a=x,b=y;
String e="";
if (isDirection(row[0])) {
for (int j = 0; j < ss.length; j++) {
e+=ds[j];
int f=calculateDirection(e);
switch (f) {
case 0: y+=Integer.parseInt(ss[j].toString());
break;
case 1:x+=Integer.parseInt(ss[j].toString());
break;
case 2: y-=Integer.parseInt(ss[j].toString());
break;
case 3:x-=Integer.parseInt(ss[j].toString());
break;
}
}
}
else {
y+=Integer.parseInt(ss[0].toString());
for (int j = 0; j < ds.length; j++) {
e+=ds[j];
int f=calculateDirection(e);
if (j<ss.length-1) {
switch (f) {
case 0: y+=Integer.parseInt(ss[j+1].toString());
break;
case 1:x+=Integer.parseInt(ss[j+1].toString());
break;
case 2: y-=Integer.parseInt(ss[j+1].toString());
break;
case 3:x-=Integer.parseInt(ss[j+1].toString());
break;
}
}
}
}
System.out.println(Math.sqrt((x-a)*(x-a)+(y-b)*(y-b)));
}
}
/**
* 判断是数字还是方向字符
* @param ch
* @return
*/
public static boolean isDirection(char ch) {
if (ch>=48&&ch<=57) {
return false;
}
else {
return true;
}
}
/**
* 这里计算多个方向符在一起到底是什么方向,都共有90度角,所以这里以4代表360度
* @param string
* @return
*/
public static int calculateDirection(String string) {
int angle=0;
char[] chs=string.toCharArray();
for (int i = 0; i < chs.length; i++) {
if (chs[i]=='L') {
angle-=1;
}
else {
angle+=1;
}
}
//因为-1向四取余是-1而不是3
return (angle+100)%4;//加了100后,0,1,2,3对应的方向是上右下左
}
}