11 Ocak 2013 Cuma

回文結構數字


問題描述
輸入兩整數,找出兩整數區間內所有具有回文結構的數字。比如說,輸入 80 100 ,則輸出為 88 99 。 100 200 ,則輸出為 101 111 121 131 141 151 161 171 181 191 。若沒有則輸出 0 。
輸入格式 
輸入 兩整數。
輸出格式 
輸出為 區間內所有具有回文結構的數字 。
Example
Sample Input:Sample Output:
80 100
100 200
88 99
101 111 121 131 141 151 161 171 181 191


  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3. #include <math.h>  
  4.   
  5. int PalindromicNum(int temp,int c){  
  6.     int i,a,b;  
  7.         for(i=0;i<=c/2;i++){  
  8.         a=temp/(int)floor((pow(10,i)));  
  9.         a=a%10;  
  10.         b=temp/(int)floor(pow(10,c-i-1));  
  11.         b=b%10;  
  12.         if(a!=b){  
  13.             return 0;  
  14.         }  
  15.     }  
  16.     return 1;  
  17. }  
  18.   
  19. int main(){  
  20.     int num1,num2,i,c,flag=1;  
  21.     scanf("%d%d",&num1,&num2);  
  22.     for(i=num1;i<=num2;i++){  
  23.         c=computeD(i);  
  24.         if(PalindromicNum(i,c)==1){  
  25.             if(flag==1){  
  26.                 printf("%d",i);  
  27.                 flag=0;  
  28.             }else{  
  29.                 printf(" %d",i);  
  30.             }  
  31.         }  
  32.     }  
  33.     if(flag==1){  
  34.         printf("0\n");  
  35.     }else{  
  36.         printf("\n");  
  37.     }  
  38.       
  39.     system("PAUSE");  
  40.     return 0;  
  41. }  
  42.   
  43. int computeD(int temp){  
  44.     int i,c;  
  45.     for(i=0;temp>0;temp/=10,i++);  
  46.     return i;  

Hiç yorum yok:

Yorum Gönder

Binary Conversion

Problem Description Convert two binary numbers into two decimal numbers and compute their sum. Your program has to convert two binary number...