introduction A beautiful programmer came to our team, and I was secretly delighted. Haha, this is my chance. I was thinking how to start? Well, I'll start with the QQ number. I'll find the goddess and get her QQ number. Haha, I'm such a genius~~~ It's like this The idea is beautiful, but the reality is cruel. When I asked the goddess for her QQ number, I didn't expect that the goddess didn't give it to me directly, but gave me a question (it's really a programmer's competition~~ ~). If I can't solve the problem, not only will I lose the opportunity to contact the goddess, but even the basic skill for survival - programming ability will be questioned~~~ The question is this:
That's it. The goddess gave a string of numbers 631758924. Now what we need to do is to find the goddess' QQ number from this number. There are many ways to do it. For example, you can use 9 cards to write these 9 numbers respectively, simulate the process of the question, and calculate it, or you can use a pen to calculate one by one~~~~ These methods are too low-level and do not show the ability of programmers. It is cooler to write a program (actually, I am thinking that if I meet a goddess who asks such a question next time, the program will be very convenient, haha~~~) Solution The first method uses mathematical methods. According to the rules of the question, loop the following operations: round up => remainder => remainder*10+round up. ... The objects of the remainder and round up are all multiples of 10. Depending on the number of digits, each rounding results in a single digit. Loop until the number is equal to 0.
Use the queue's FIFO to obtain the QQ number. According to the characteristics of the question, the queue can be used to process it. The queue is simple, convenient, and easier to understand.
Congratulations, you have successfully obtained the QQ number: 615947283. Please press any key to continue. . . Say something The idea for this article comes from Chapter 2, Section 1 [Decrypting QQ Numbers — Queues] in Aha! Algorithms, and the only illustration is also taken from this book. ------------------------------------Dividing line------------------------------------ The js of @朱影 on the 21st floor uses array push and shift, which is also good (slightly modified), "push first and then shift":
|
<<: 10 Steps to Becoming a Professional iOS Developer — From Scratch
>>: Make your PHP 7 faster (GCC PGO)
Preface A qualified code should not only realize ...
[September 9, 2020] WM Motor, the leading smart c...
Mixed Knowledge Specially designed to cure confus...
Author: Wang Pingguo Reviewer: Pang Yufeng, Deput...
The artificial intelligence (AI) market is beginn...
It has only been a few months since Apple's n...
After the Qingming Festival, the temperature bega...
With the rapid development of the Internet , we h...
As we enter 2022, the epidemic, which had been do...
In order to conduct this experiment, scientists a...
[[225216]] I am doing it myself now, but I have b...
The impact lasts for decades. On May 18, 1980, Mo...
Reuters quoted technology blog Information as say...
On the morning of January 9, the 2019 WeChat Open...
Author: Duan Yuechu, Huang Xianghong, Huang Yanho...