Filter strings (Java)

Source: Internet
Author: User

/*
Enter a string of lowercase letters (A~Z) through the keyboard. Write a string filter to filter out characters that are not the first occurrence if multiple identical characters appear in the string.
For example, the string "ABACACDE" filter result is "ABCDE".
Required implementation functions:
void Stringfilter (const char *PINPUTSTR, long Linputlen, Char *poutputstr);
"Input" PINPUTSTR: input string
Linputlen: Input string length
"Output" POUTPUTSTR: output string, space has been opened up, and input string length;
"Note" Only needs to complete the function algorithm, the middle does not need any IO input and output
Example
Input: "DEEFD" Output: "Def"
Input: "AFAFAFAF" Output: "AF"
Input: "PPPPPPPP" Output: "P"

*/

1  PackageHuawei Machine test;2 3 4 ImportJava.util.Scanner;5 6 7  Public classMain2 {8 9      Public Static voidMain (string[] args) {Ten         //TODO auto-generated Method Stub OneScanner scn=NewScanner (system.in); AString s=Scn.next (); -         Charc[]=S.tochararray (); -         Booleanexit[]=New Boolean[26]; the         intIndex=0; -          -          for(inti=0;i<c.length;i++) -         { +             if(!exit[c[i]-' a ']) -             { +exit[c[i]-' A ']=true; Ac[index++]=C[i]; at             } -              -         } -System.out.println (NewString (c). substring (0, index)); -     } -  in}

Filter strings (Java)

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.