Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language programming problem, plastic internal code symmetry problem.
C language programming problem, plastic internal code symmetry problem.
# include & ltiostream & gt

# include & ltstdio.h & gt

Use namespace std

int panduan(char *s)

{

int i,flag = true

//Because we know that 32 is an integer, sometimes the parameter can be a constant (such as I

for(I = 0; I< 16; i++)

{

If (s[i]! =s[3 1-i])

{

flag = false

Break; //If the asymmetry is known, the loop can exit early.

}

}

Return flag;

}

int main()

{

int a;

int counter = 0;

//CIN & gt; & gta and scanf ("%d ",&; A)! =EOF is different

//When a=- 1, the former will think it is the end of the file, while the latter will not.

While(scanf("%d ",&a)! = EOF)

{

char s[32];

for(int I = 0; I & lt32; i++)

{

s[I]= a % 2; //Use a&; 1 is better because bit operations are faster than modulo operations.

a & gt& gt= 1; //a=a/2 cannot be used here. If a is negative, the division operation will not move the sign bit 1.

}

if(panduan(s)== 1)

counter++;

}

Cout & lt& lt counter & lt& ltendl

Returns 0;

}