4. The primary series caught committing traffic accident problem

Caught committing traffic accident

Problem Description
A truck traffic violation, gave the driver fled the scene there are three witnesses to the incident, but did not remember the license plate number, just remember some of the features got the number of A said: The first two digits of the license is the same as B said : the last two digits of the license is the same, but different from the first two, propane is a mathematician, he said: four-digit license plate number is just an integer squared please obtain the license plate number of the above clues
analysis
according to subject required to construct a same first two digits, and the last two digits the same as each other and different 4-bit integer, and determines whether the square of the integer is another integer. I.e. seeking a four-digit, the following conditions are satisfied
| --a. 1 = B <= A <= 9,0 <= B <=. 9
| 0 --c = D <= C, D <=. 9
| - ! a = C
| --1 000 a 100 + B + D + 1OC ^ 2 = X, X = {Z}
algorithm design
that topic numerical calculation required to solve equations for the problem solving the indefinite variable equations, the general Exhaustive method

/* !< use c */
#include <stdio.h>

int main(void)
{
    int i, j,k,tmp; /* !< i代表前两位车牌号数字,j代表后两位车牌号的数字,k代表车牌号*/

    for (i = 0; i <= 9; i++) {
        for (j = 0; j <= 9; j++) {  /* !< 穷举前两位和后两位车牌数字*/
            /* !< 判断前两位数字和后两位数字是否不同 */
            if (i != j) {
                /* 组成4位车牌号 */
                k = 1000*i + 100*i + 10*j + j;
                /* 判断k是否是某个数的平方,若是则输出 k */
                for (tmp = 31; tmp <= 99; tmp++) {
                    if (tmp * tmp == k) {
                        printf("车牌号为%d", k);
                    }
                }
            }
        }
    }
}
/* !< use python */
for i in range(10):
for j in range(10):
    if i != j :
        k = 1000 * i + 100 * i + 10 *j + j
        for temp in range(31,100):
            if temp * temp == k:
                print("k=",k)
/* !< output */
    k= 7744

Guess you like

Origin www.cnblogs.com/xuzhaoping/p/11484484.html