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)
As we enter the second half of the Internet era, ...
Death represents the end, because everything we h...
Review expert: Zhu Guangsi, member of Beijing Sci...
Someone once commented on Cai Wensheng: "He ...
When we talk about the technology in ancient buil...
Author Li Chuanfu Elderly care robots are here! S...
Continuing from the previous article "18 det...
Are humans' ancestors fish? Chinese Academy o...
On the land of China Among thousands of rivers Ch...
Facebook unexpectedly decided to remove this key ...
Fenghe River, also known as "Fengshui" ...
According to foreign media reports, French automo...
A woman called me and asked me: Other people gain...
A few days ago, a nutritionist on a health progra...