American Regiment 2015 School Recruit Research and development pen question--alphabetical sort

Source: Internet
Author: User

Topic Source Cattle Net: http://www.nowcoder.com/questionTerminal/3c334863c02443cdb61b2d73c1edf071?orderByHotValue=0&query= A set of randomly arranged alphabetic arrays &done=0&pos=9

A set of randomly arranged alphabetic arrays. Write an algorithm with a time complexity of O (n) so that the letters are sorted from small to large in alphabetical order.

 

Description: Letters are case-sensitive, with the same letters, and lowercase are sorted before uppercase.

Example: R,b,b,b,w,w,b,r,b,w

Sorted by: B,b,b,b,b,r,r,w,w,w

1) Description Ideas (2 points)

2) Please use your familiar programming language code implementation (8 points)

Java Solution version:

import java.util.arraylist;import java.util.collection;import java.util.collections;import java.util.Vector; Public classMydemo { Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem. out. println (Function ("ABBBDSXAINIKNKDKKKKJJCCDDDCC")); }     Public Staticstring function (String inputstring) {ArrayList<Character> arraylist=NewArraylist<> ();//Save uppercase lettersArraylist<character> arraylist2=NewArraylist<> ();//Save lowercase lettersStringBuffer result=NewStringBuffer ();  for(intI=0; I<inputstring.length (); i++){            if(Inputstring.charat (i) <'a'){//Uppercase LettersArraylist.add (Inputstring.charat (i)); }Else{arraylist2.add (Inputstring.charat (i));        }} collections.sort (ArrayList);        Collections.sort (ARRAYLIST2);  for(intI=0; I<arraylist2.size (); i++) {result.append (arrayList2.Get(i)); }         for(intI=0; I<arraylist.size (); i++) {result.append (arrayList.Get(i)); }        returnresult.tostring (); }}


My Android learning experience: http://jingyan.baidu.com/season/48891

American Regiment 2015 School Recruit Research and development pen question--alphabetical sort

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.