: This article mainly describes how to find a QQ number for Goddess. if you are interested in the PHP Tutorial, refer to it. Introduction
We have a beautiful programmer in our group. I am very fond of it. haha, this is a chance. What do I want to do? Okay, I still start from the QQ number and find the goddess to go to the QQ number. haha, I am a genius ~~~
It is like this.
The idea is beautiful, and the reality is cruel. When I asked the goddess for a QQ number, I did not expect the goddess to give it to me directly, but gave me a question (if it is really a programmer's hand ~~ ~), I have given my questions. if I cannot do anything, I will not only lose the chance of getting in touch with the goddess, but even the basic skills on which I live-programming skills have been questioned ~~~ The question is as follows:
Given a string of numbers (not QQ numbers), follow the rules below to find the QQ number: first delete the first number, then put the second number at the end of the string, and then delete the third number, place the fourth number at the end of the number string ...... in this loop, you will know the last number and delete the last number. in the order of deletion, connecting these numbers together is the QQ number of goddess.
In this way, the goddess gave a string of numbers 631758924. now, we need to find the QQ number of the goddess from this number. There are many ways to do this, for example, you can use 9 cards to write these 9 numbers separately to simulate the question objective process. you can also use a pen to calculate the numbers one by one ~~~~
These methods are too low to show the programmer's ability. it is cool to write a program. (in fact, I am thinking that if I encounter another goddess with such a question next time, the program is very convenient, haha ~~~)
Solution
The first method is to use the mathematical method. according to the law of the question, perform the following operations in a loop: Get the integer => get the remainder * 10 + get the integer ..... The remainder object is a multiple of 10. it depends on the number of digits. after each integer is obtained, it is a bit and the number is equal to 0.
0) {$ devisor/= 10; $ next = floor ($ raw_num/$ devisor); // get the next number $ num = $ num * 10 + $ next; // calculate the "semi-finished product" QQ number $ raw_num = $ raw_num % $ devisor; $ last = floor ($ raw_num * 10/$ devisor); // move the number, splice the latest QQ number $ pre = $ raw_num % (ceil ($ devisor/10); $ raw_num = $ pre * 10 + $ last;} echo "Congratulations, QQ number: {$ num} "; // Congratulations! QQ number: 615947283
Obtain the QQ number using the FIFO queue. based on the characteristics of the question, the queue can be used for processing. the queue is simple and convenient, and can be better understood.
# Include
Struct queue {int * data; int head; int tail ;}; int main () {int num, I; printf ("Please output the length of the QQ number to be decrypted :"); scanf ("% d", & num); struct queue q; q. data = (int *) malloc (sizeof (int) * (num * 2-1); // The total length of the expected array is num * 2-1 q. head = 0; q. tail = 0; for (I = 1; I <= num; I ++) {scanf ("% d", & q. data [q. tail]); q. tail ++;} printf ("Congratulations, you have obtained the QQ number:"); while (q. head <q. tail) {printf ("% d", q. data [q. head]); q. head ++; q. data [q. tail] = q. data [q. head]; q. tail ++; q. head ++;} return 0 ;}# below is an experiment. please output the length of the QQ number to be decrypted: 9631758924. Congratulations, you have obtained the QQ number: 615947283. press any key to continue...
What do you mean?
This article comes from aha! In the second chapter of the algorithm, section 1 [decrypts the QQ number-queue]. the only illustration is also taken from this book.
No.: love_skills
The harder you work, the luckier you are! The luckier you are, the harder you work!
It's not a dream to become a CEO.
It's not a dream to win Bai Fumei
Yundun attack is not a dream
Now !! Fuel
The above describes how to find a QQ number for goddess, including the content, and hope to be helpful to friends who are interested in PHP tutorials.