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 a gathering place for Generation Z, Bilibili a...
In October, three consecutive spontaneous combust...
Operation refers to all work related to the post-...
In recent years, mobile Internet has developed ra...
[[121822]] Android 5.0 is a major system update. ...
The main factors affecting the price of mini prog...
What should you do if your phone runs out of spac...
The article I wrote recently discussed the issue ...
In January of this year, Google submitted a code ...
Influenced by traditional Chinese culture, people...
Let's do a test first. Please close your eyes...
Recently, two Russian astronauts on the Internati...
"During an epileptic seizure, putting someth...
For me, WeChat not only meets my daily communicat...
Qiān (qiān) is a plant that is both familiar and ...