Used to keep track of what's going on in actual programming and keep updating.
Such as:
Develop a coordinate calculation tool, a for moving to the left, D for moving to the right, W for moving up, and s for moving down. Moves from the (0,0) point, reads some coordinates from the input string, and outputs the final input to the output file. Input: The legal coordinates are a (or D or W or s) + number (within two digits), and the coordinates are separated by; Illegal coordinate points need to be discarded. such as AA10; A1A; $%$; YAD; such as
ImportJava.util.*;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern; Public classMain { Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); while(Scanner.hasnext ()) {String input=Scanner.next (); String[] Arr= Input.split (";"); String pattern= "[adws][0-9]{1,2}"; Pattern R=Pattern.compile (Pattern); List<String> list =NewArraylist<string>(); for(inti=0;i<arr.length;i++) {Matcher m=R.matcher (Arr[i]); //The find () method is a partial match//matches () is the full match if(M.matches ()) {List.add (M.group ()); } } intX=0, y=0; for(intI=0;i<list.size (); i++) { CharDirection = List.get (i). CharAt (0); intLen = integer.valueof (List.get (i). SUBSTRING (1)); //System.out.println (len); Switch(direction) { Case' A ': X-=Len; Break; Case' D ': x + =Len; Break; Case' W ': y + =Len; Break; Case' S ': y-=Len; Break; default: Break; }} System.out.println (x+","+y); } scanner.close (); }}
Java Regular Expressions