Java implementation-201,600 degrees autumn strokes (color reversal, similar string)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.