?? robots.java
字號(hào):
package robots;
import java.util.*;
import java.io.*;
public class Robots {
Robots()
{}
String[] plain= new String[100];
char direction;
int s=0,q=0,s1=0,q1=0,i;
public String[] getstring()throws Exception/*得到每一行字符串*/
{
Scanner scanner=new Scanner(new File("input.txt"));
String line;
for(this.i=0; (line=scanner.nextLine()).compareTo("n")!=0; this.i++)
{plain[this.i]=line;
}
return plain;
}
public void matrix(String num)/*首行解決方案*/
{
s=(int)(num.charAt(0))-48;
q=(int)(num.charAt(2))-48;
}
public char beginning(String num)/*次行解決方案*/
{
s1=(int)(num.charAt(0))-48;
q1=(int)(num.charAt(2))-48;
direction=(num.charAt(4));
return(direction);
}
public void move()/*行進(jìn)方法*/
{switch(direction)
{case 'N': q1=q1+1; break;
case 'S': q1=q1-1; break;
case 'E': s1=s1+1; break;
case 'W': s1=s1-1; break;
}
}
public void turn(char control)/*轉(zhuǎn)向方案*/
{
switch(direction)
{case 'N': if(control=='L') direction='W';
else direction='E'; break;
case 'S': if(control=='L') direction='E';
else direction='W'; break;
case 'E': if(control=='L') direction='N';
else direction='S'; break;
case 'W': if(control=='L') direction='S';
else direction='N'; break;
}
}
public void moving(String num)/*移動(dòng)方案*/
{int length=num.length();
for(int z=0;length!=0;z++,length--)
{switch(num.charAt(z))
{case 'M': move(); break;
case 'L': turn('L');break;
case 'R': turn('R');break;
}
}
}
public void choosestring(String num,int number)/*辨別使用哪個(gè)查找,string num為字符串,int number為的幾行*/
{if(number==0)
this.matrix(num);
else if(number%2==1)
this.beginning(num);
else if(number%2==0)this.moving(num);
if(number!=0 && number%2==0)
System.out.print("the consequence is "+s1+","+q1);
}
public static void main(String[] args)throws Exception
{ Robots arobot=new Robots();
arobot.getstring();
System.out.print(arobot.getstring());
for(int k=0;arobot.i!=0;k++,arobot.i--)
{System.out.print(arobot.plain[k]);
arobot.choosestring(arobot.plain[k],k);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -