Topic Description
Develop a coordinate computing tool, a means to move left, D to move to the right, W to move up, and s to move down. Move from the (0,0) point, read some coordinates from the input string, and output the final input results to the output file.
Input:
Valid coordinates are a (or D or W or s) + digits (two digits)
to divide between coordinates;
Illegal coordinate points need to be discarded. such as AA10; A1A; $%$; YAD; Wait
The following is a simple example:
A10; S20; W10;d30; X A1A; B10A11;; A10;
Processing process:
Beginnings (0,0)
+ A10 = ( -10,0)
+ S20 = ( -10,-20)
+ W10 = ( -10,-10)
+ D30 = (20,-10)
+ x = Invalid
+ A1A = Invalid
+ B10A11 = Invalid
+ A null does not affect
+ A10 = (10,-10)
Results (10,-10)
Enter a description:
One-line string output Description:
Final coordinates, to separate example 1 input
A10; S20; W10;d30; X A1A; B10A11;; A10;
Output
10,-10
This program is very difficult to see, but the same is very simple, just a few simple addition operations.
public static void Main (string[] args) {
Scanner sc=new Scanner (system.in);
while (Sc.hasnext ()) {
String s = sc.nextline ();
String[] A = S.split (";");
int x=0;
int y=0;
for (int i = 0;i<a.length;i++) {
if (A[i].charat (0) = = ' A ' &&a[i].substring (1). Matches ("[0-9]{1,2}")] {
x-= Integer.parseint (a[i].substring (1));
}
if (A[i].charat (0) = = ' S ' &&a[i].substring (1). Matches ("[0-9]{1,2}")) {
Y-=integer.parseint (a[i].substring (1));
}
if (A[i].charat (0) = = ' W ' &&a[i].substring (1). Matches ("[0-9]{1,2}")) {
Y+=integer.parseint (a[i].substring (1));
}
if (A[i].charat (0) = = ' D ' &&a[i].substring (1). Matches ("[0-9]{1,2}")) {
X+=integer.parseint (a[i].substring (1));
}
}
System.out.println (x+ "," +y);
}
}