Home > headlines > How do programmers solve difficult problems and get the goddess's QQ account?

How do programmers solve difficult problems and get the goddess's QQ account?

小云云
Release: 2017-11-07 11:50:25
Original
2343 people have browsed it

I met a goddess and thought that I could win her heart with my looks, so I took the initiative to ask for a QQ account from the goddess. Unexpectedly, the beauty guide failed. The goddess gave me a question. It seemed that she was really a programmer. A contest between the two, the title is as follows:
The goddess gave a string of numbers (not QQ numbers), the QQ number can be found according to the following rules: first delete the first number, and then put the second number At the end of this string of numbers, delete the third number, and put the fourth number at the end of this string of numbers... In this loop, until the last number is left, delete the last number, and delete it as you just did In order, connect these numbers together to get the goddess’s QQ number.

How do programmers solve difficult problems and get the goddesss QQ account?

That’s it, the goddess gave a string of numbers 631758924. What we have to do now is to find out the goddess’s QQ number from this number. There are many ways, such as Use 9 cards to write these 9 numbers respectively, and simulate the process of the question. You can calculate them, or you can use a pen to calculate them one by one~~~~

These methods are too low and cannot be displayed. As for the ability of a programmer, it would be cooler to write a program (actually, I was thinking, if I encounter a goddess asking such a question next time, the program would be very convenient, haha~~~)

Solution Method

The first method is to use mathematical methods and cycle the following operations according to the rules of the question: rounding => remainder => remainder * 10 + rounding. . . . . The objects of remainder rounding are all multiples of 10, depending on the number of digits. After each rounding, there is one digit, and the loop is continued until the number is equal to 0.

$raw_num = 631758924;

$num = 0;

$devisor = 1;

while ($devisor

{

$devisor *= 10; //Get the smallest integer that is a multiple of 10 of raw_num

}

while ($raw_num > 0) {

$devisor /= 10;

$next = floor($raw_num / $devisor); // Get the next number

$num = $num*10 + $next; $last = floor($raw_num * 10 / $devisor); //Move the numbers and splice the latest QQ number

$pre = $raw_num % (ceil($devisor / 10) );

$raw_num = $pre * 10 + $last;

}

echo "Congratulations, you successfully obtained your QQ number: { $num}"; //Congratulations, you successfully obtained the QQ number: 615947283

Use the FIFO of the queue to obtain the QQ number. According to the characteristics of the question, you can just use the queue to process it. The queue is simple, convenient, and better understand.

#include

struct queue {

int *data;

int head;

int tail;

};

int main()

{

int num, i;

printf("Please output the code to be deciphered QQ number length: ");

scanf("%d", &num);

struct queue q;

q.data = ( int *)malloc(sizeof(int)*(num*2-1)); //The total required array length is num*2-1

q.head = 0;

q.tail = 0;

for(i=1;i

{

scanf("%d" , &q.data[q.tail]);

q.tail++;

}

printf("Congratulations, you successfully obtained QQ Number: ");

while(q.head

{

printf("%d", q.data[q.head] );

q.head++;

q.data[q.tail] = q.data[q.head]; tail++;

q.head++;

}

return 0;

}

#The following is An experiment

Please output the length of the QQ number to be deciphered: 9

Please output the length of the QQ number to be deciphered: 9

6

3

1

7

5

8

9

2

4

Congratulations, you successfully obtained the QQ number: 615947283. Please press any key to continue... Now my status in the heart of the goddess has been greatly improved.

How about it? Have you learned this method?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template