Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language programming to find Sisyphus strings
C language programming to find Sisyphus strings
It took me a long time, and you didn't give me a penny, which made me feel very sorry.

/* According to my own summary, it is. The last number is calculated by myself anyway, and it should be over.

*/

# include & ltstdio.h & gt

# include & ltstring.h & gt

# Define ARRAY_LEN 100

The order of parameters when plastic is converted into string is: string is used to save the converted value, the value to be converted and the number of characters after conversion */char * itostr (char * s, int value, int * num).

{

int I = 0;

int modtmp = 0;

int tmp = value

int j = 0;

char ctmp =“0”;

* num = 0; /* After entering the function, rewrite it to 0 to prevent it from affecting the following */

/* Split integers into arrays */ while (0! = tmp)

{

modtmp = tmp % 10;

s[i++]= modtmp+' 0 ';

tmp = tmp/ 10;

}

s[I]= ' \ 0 '; /* Set the last one to 0 */

/* Because the converted value is flashback, the reverse direction */for (j = 0; j & ltI/2; j++)

{

ctmp = s[j];

s[j]= s[I-j- 1];

s[I-j- 1]= ctmp;

}

* num = I;

Return to s; }

char* fun(char a[]){

char * pTmp = a;

int odd num = 0; //Odd int eventnum = 0; //Even number

int total num = 0;

int I = 0;

char CSTR[20]= { 0 }; char * pcstr = cstr

int cnum = 0; /* Record how many characters there are after the integer is converted into a string */

int tmp = 0;

/* Record odd and even totals */for (; *pTmp! = '\0'; ++pTmp)

{

tmp = * pTmp-' 0 ';

if(0 & lt; tmp & amp& amptmp & lt= 9)

{

if(tmp % 2 == 0)

{

even num++;

}

other

{

odd num++;

}

total num++;

}

other

{

Break; //Encountered a character that is not a number.

}

}

/* I can't think of a better way to construct three numbers into a string */it ostr (PC str, evenum,&; cnum);

pcstr = pcstr+cnum;

iToStr(pcstr,oddNum,& ampcnum);

pcstr = pcstr+cnum;

iToStr(pcstr,totalNum,& ampcnum);

printf("%s \n ",CSTR);

if (0 == strcmp(a,cstr)) {

/* If the calculated value is equal to itself, */

memcpy(a、cstr、strlen(CSTR));

a[strlen(CSTR)]= ' \ 0 ';

Return to a;

}

other

{

Return of funds (CSTR);

}

}

void main(){

char a[ARRAY _ LEN];

Printf ("Please enter a numeric string:");

int b = 0;

fgets(a,ARRAY_LEN,stdin); //This will not cause overflow.

Printf ("the mysterious number is: %s\n", fun (a)); }