Blue Bridge Cup. Take characters (remove duplicates using the Set list implementation)

Source: Internet
Author: User

Title Description:

Reads a string of letters (no more than 30 characters) from the keyboard.

Remove 3 non-repeating characters from the string and ask for all the extraction.
The characters that are removed require a string in ascending alphabetical order.
Different output sequences can be used without consideration.
For example:
Input:
Abc
The output:
Abc
Input:
Abcd
The output:
Abc
Abd
Acd
Bcd
Input:
Abcaa
The output:

Abc

Package Ccf;import Java.util.arraylist;import Java.util.hashset;import java.util.linkedhashset;import Java.util.list;import Java.util.scanner;import Java.util.set;public class Getthree_nnorepeat_from_string {public static void Main (string[] args) {Scanner s=new Scanner (system.in); String string = S.next ();p rintabc (Getcharset (String));} public static set<character> Getcharset (String s) {//Because the set collection is non-repeatable and the linedhashset is stored orderly//here is to ensure ordering of the order of additions: for example, A, B, c The resulting set is [a,b,c]. If the use of hashset results for [b,a,c] can not guarantee the storage of ordered set<character> charset=new linkedhashset<character> (); for (int i=0;i<s.length (); i++) {Charset.add (S.charat (i)),//Converts a string into a character into a set set, and the set set does not contain duplicates}system.out.println ( CharSet); return charSet;} public static void Printabc (Set<character> charSet) {//Because the set set is unordered, the set set is converted to listlist<character> list= New Arraylist<character> (CharSet); for (int i = 0, I < list.size ()-2; i++) {for (int j = i + 1; J &lt ; List.size ()-1; J + +) {for (int k = j + 1; k <List.size (); k++) {System.out.print (List.get (i));                    System.out.print (List.get (j));                    System.out.print (List.get (k));                System.out.println (); }            }        }}}
Operation Result:

Abcdabcd
[A, B, C, d]
Abc
Abd
Acd
Bcd

Blue Bridge Cup. Take characters (remove duplicates using the Set list implementation)

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.