- /*
- ============================================================================
- Name : huiwenshu.c
- Version :
- Copyright : Your copyright notice
- Description : Hello World in C, Ansi-style
- ============================================================================
- */
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc ,char **argv)
- {
- //ch 必须是一个回文数
- char ch[12]={"999999999"};
- int count = strlen(ch);
- int i,j;
- while(ch[0] != '0')
- {
- printf("%s\\n",ch);
- if(count == strlen(ch))
- {
- if(strlen(ch)%2 != 0)
- i = j = strlen(ch)/2;
- else
- {
- i = strlen(ch)/2-1;
- j = strlen(ch)/2;
- }
- count --;
- }
- if(i == j)
- {
- ch[i]--;
- if(ch[i] == '0'-1)
- {
- ch[i] = '9';
- i--;
- j++;
- }
- }
- else
- {
- ch[i]--;
- ch[j]--;
- if(ch[i] == '0'-1)
- {
- ch[i] = ch[j] = '9';
- i--;
- j++;
- }
- else
- {
- if(strlen(ch)%2 != 0)
- {
- i = j = strlen(ch) / 2;
- }
- else
- {
- i = strlen(ch) /2-1;
- j = strlen(ch) / 2;
- }
- }
- if(ch[0] == '0')
- {
- int k;
- for(k=0;k<count;k++)
- {
- ch[k] = '9';
- }
- ch[count] = '\\0';
- }
- }
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/130220148716.html
来源: http://www.codesnippet.cn/detail/130220148716.html