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)
I just saw a Weibo post about Zuckerberg's ex...
Douyin became a huge hit like a bolt from the blu...
Promotional methods + operational knowledge = imp...
Many people often say that they can’t find the fe...
Small pancake oven with dip "Soul BBQ Three-...
[[142625]] Before we get started, I'd like to...
There are no conventional theories here, only new...
This article was first published by Hunzhi (WeCha...
In August 2023, driven by national policies to bo...
This article will analyze the 618 activities of o...
After the Shanghai Pudong New Area implemented ful...
Volkswagen released its global delivery data for ...
People always overestimate the changes in the nex...
Spanning 5,000 years, more than 210 pieces/sets o...