1031. speed seek

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_16525829/article/details/102773065

Title Description

A car traveling at a constant speed, the driver can see at 10 o'clock in the morning reading on the odometer is a symmetrical number (ie the number read from left to right and right to left reading are exactly the same), to 95,859. Two hours later there was a new symmetric number on the odometer. Q. What is the speed of the car? The new number is the number of symmetry?

## Sample Output
95959

Tip
meaning of the questions, ask disposed symmetrically number i, which is the initial value 95589, its value in ascending order, each i is an exploded value after comparing the number of its symmetrical position, if each of the symmetrical positions number are equal, it is judged that the number i is also desired symmetry of.

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a=95589;
    int b,m,x,z,n;
    while(a++)
    {
        z=0;
        n=a;
        b=ceil(log10(a));
        m=pow(10,b-1);
        for(int i=0;i<b;i++)
        {
            x=a/m*pow(10,i);
            a=a%m;
            m=m/10;
            z=z+x;
        }
        a=n;
        if(a==z)
        {
        cout<<z;
        break;
        }
    } 
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_16525829/article/details/102773065