HDU1282+水题+模拟

View Code
 1 /*

 2 模拟+回文数

 3 */

 4 #include<stdio.h>

 5 #include<string.h>

 6 #include<stdlib.h>

 7 #include<algorithm>

 8 #include<iostream>

 9 #include<queue>

10 #include<vector>

11 #include<map>

12 #include<math.h>

13 typedef long long ll;

14 //typedef __int64 int64;

15 const int maxn = 105;

16 const int maxm = 1005;

17 const int inf = 0x7FFFFFFF;

18 const double pi = acos(-1.0);

19 const double eps = 1e-8;

20 using namespace std;

21 int a[ maxn ];

22 

23 int judge( int n ){

24     int pren = n;

25     int newn[ 105 ];

26     int len = 0;

27     while( n!=0 ){

28         newn[ len++ ] = n%10;

29         n/=10;

30     }

31     int nown = newn[0];

32     for( int i=1;i<len;i++ ){

33         nown*=10;

34         nown += newn[i];

35     }

36     //printf("nown:%d\n",nown);

37     if( pren==nown ) return -1;//正序和倒序是相同的

38     else return (pren+nown);

39 }

40         

41 int main(){

42     int n;

43     while( scanf("%d",&n)!=EOF ){

44         int cnt = 0;

45         if( judge(n)==-1 ){

46             printf("0\n");

47             printf("%d\n",n);

48             continue;

49         }

50         a[ cnt++ ] = n;

51         while( 1 ){

52             a[ cnt++ ] = judge( n );

53             n = a[ cnt-1 ];

54             if( judge(n)==-1 ){

55                 //a[ cnt++ ] = n;

56                 break;

57             }

58         }

59         

60         printf("%d\n",cnt-1);

61         for( int i=0;i<cnt;i++ ){

62             if( i==0 ) printf("%d",a[0]);

63             else printf("--->%d",a[ i ]);

64         }

65         printf("\n");

66     }

67     return 0;

68 }    

 

你可能感兴趣的:(HDU)