"Find the Goddess to QQ number"--the follow-up Java Novice version (for guidance)

Source: Internet
Author: User

After eating zongzi, nothing to do, so prepare to look inside the garden. Suddenly saw a "find Goddess to qq number" article, suddenly energetic ~ ~ ^_^.

The article landlord shows that this algorithm comes from "Ah ha!" Algorithm ", illustrated, very good. "Ah ha!" Algorithm ". PDF:HTTP://VDISK.WEIBO.COM/S/ZZBPQZW3MPNBM

It was just a look, the results found that the comments are very hot, are sending their own implementation code.

For example: Beauty programmer is how to convert QQ into the title of the string of numbers-read the blog "to find the goddess QQ number" http://www.cnblogs.com/net-xiejun/p/4589594.html, etc.

I will be waiting for beginners to join in the fun.

The question is this:

Give a bunch of numbers (not QQ number), according to the following rules can find QQ number:

First the first number is deleted, and then the second number is placed at the end of the string, the third number is deleted, and the fourth number is placed at the end of this string of numbers ...

So loop, know the last number left, and delete the last number

According to the order just removed, the number of these numbers together is the goddess QQ number.

The Java code is as follows:

Importjava.util.LinkedList;ImportJava.util.Queue; Public classYule {PrivateString QQ;  PublicYule (String qQ) { This. QQ =QQ; }         PublicString getqq () {returnQQ; }     Public voidsetqq (String QQ) {QQ=QQ; }         PublicString getrealqq () {StringBuffer sb=NewStringBuffer (); intn = 1; String str1= ""; Queue<String> queue =NewLinkedlist<string>();  for(intI =0; i<qq.length (); i++) {Queue.add (string.valueof (Qq.charat (i))); }                 while((str1 = Queue.poll ())! =NULL){            if(n%2 ==0) {queue.add (STR1); }Else{sb.append (STR1); } N++; }        returnsb.tostring (); }         Public Static voidMain (string[] args) {System.out.println ("Goddess QQ number is:" +NewYule ("631758924"). GETREALQQ ()); }}

The operation result is: "Goddess QQ number is: 615947283"

The result equals the answer.

Look at your own code, and then look at other people's code, total sleep is very bloated, very eager to write the code more incisive, elegant, but the level is limited.

The reason why you want to first page, only one, hope to see this article of the great God, can help me to make suggestions, how to optimize the code, thank you very much!

"Find the Goddess to QQ number"--the follow-up Java Novice version (for guidance)

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.