1. Color reversal
Title Description:
In WEB development, a color is typically represented by a 16-binary RGB. For example #0000FF is blue, #FF7F50 means coral red. In this problem, we ask for a given color to be reversed, by converting each bit of RGB to decimal RGB, then subtracting it by 255, and converting it into 16 binary. For example blue inversion is yellow (#FFFF00).
Input: #0000FF #FFFF00
Output: #FFFF00 #0000FF
Importjava.util.ArrayList;Importjava.util.List;ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); while(Sc.hasnext ()) {System.out.println (Sc.nextline ())); } sc.close (); } Public Staticstring Reserve (String str) {StringBuilder SB=NewStringBuilder (). Append ("#"); for(intI=1;i<str.length (); i++) {String St=str.charat (i) + ""; intTemp=integer.parseint (st,16); Sb.append ("" +integer.tohexstring (15-temp). toUpperCase ()); } returnsb.tostring (); }}
2. Similar string
Title Description:
S and T are two strings (they consist only of lowercase letters), defining S is similar to t when and only if:
1, S and T are the same length.
2. For any two positions I and J, if Si and SJ are the same, then Ti and TJ are the same; if Si and SJ are different, then ti and TJ are different. (Si means the character of the string s in the position I, the meaning of TI is the character of the string T in the first position) with the string "ABCA" similar to the strings have "ABCA", "Cdac", "Zetz" and so on, now give a string s, output a similar dictionary order the smallest string.
Input: HelloWorld output: ABCCDEDFCG
ImportJava.util.HashMap;ImportJava.util.Map;ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); String Str=Sc.nextline (); SYSTEM.OUT.PRINTLN (Findrealstr (str)); Sc.close (); } Public Staticstring Findrealstr (String str) {HashMap<Character,Character> map=NewHashmap<character, character>(); StringBuilder SB=NewStringBuilder (); CharC= ' a '; for(intI=0;i<str.length (); i++){ Chartemp=Str.charat (i); if(NULL==Map.get (temp)) {Map.put (temp,c++); } sb.append (Map.get (temp)); } returnsb.tostring (); }}
Java implementation-201,600 degrees autumn strokes (color reversal, similar string)