#include <iostream> #include <cstring> using namespace std; int main(){ char a[255]; cin >> a; int len = strlen(a); int s = 0,count = 0; while(true){ if(a[len/2-s-1]==a[len/2+s]){ count++; s++; } else break; } cout << count << endl; return 0; } 

Degree of symmetry

The degree of symmetry of a natural number is the number of pairs of its decimal digits, in which the digits match and are located symmetrically about the middle of the decimal notation of this number. If a certain number is in the middle of the decimal notation, it must also be taken into account together with it. Find the degree of symmetry of the number n.

Input data

One positive integer n (n < 2 ·10^9) .

Output

Derive the degree of symmetry of the number n . As a result, three correct answers out of 10.

    1 answer 1

    This cycle

     while(true){ if(a[len/2-s-1]==a[len/2+s]){ count++; s++; } else break; } 

    leads to indefinite program behavior, since there is no check in it whether the output from the array has occurred or not.

    In addition, if the number contains an odd number of digits, such as 12321 , then

     Len / 2 

    will be 2. As a result, the first iteration of the cycle compares the elements in positions 1 ( len/2-s-1 ) and 2 ( len/2+s ), which correspond to the numbers 2 and 3, and the result is incorrect.

    • Yes, indeed, I did not consider the option with an unpaired number of digits. - goodalien