voip
风的方向
厚德致远,博学敦行!
posts - 52,comments - 21,trackbacks - 0
     今天培训的老师让我们做的题目。。。
     我写了几个(不多说了比较累直接上代码了):
#include<stdio.h>
#include
<string.h>
#include
<math.h>
#include
<stdlib.h>
void Numtostring(int num,char s[])  //自定义数字转换成字符串函数 
{
    
int temp,i=0;
//    char *s;
//    s=(char *)malloc(500); 
    
//char s[500];
    while(num!=0)
    
{
        temp
=num%10;
        s[i]
=temp+48;
        i
++;
        num
=num/10;    
    }

    s[i]
='\0';
    strrev(s);
}

int NumberTest0(int num)  //数字逆序,返回逆序值 
{
    
int temp;
    
int n,i;
    
int num0=0;
    n
=log10(num);
    printf(
"n=%d\n",n);
    
for(i=n;i>=0;i--)
    
{
        temp
=num%10;
        num
=num/10;
        num0
+=temp*pow(10,i);
        printf(
"num0=%d\n",num0);
    }

    
return num0;    
}

int StringTest(int num)//回文判断,字符串逆转思路 
{
    
char s[500],s1[500];
    Numtostring(num,s);
//数字转换成字符串函数 
    puts(s);
    strcpy(s1,s);
    strrev(s1);
    
if(strcmp(s1,s)==0)
        printf(
"Yes\n");
    
else
        printf(
"No\n");
    
return 0;
}


int NumberTest1(int n)//回文判断 老师解题思路 听说是大神级的人物写的。。。
{
    
int temp=0;
    
int m=n;
    
while(n)
    
{
        temp
=temp*10
        temp
+=n%10;
        n
=n/10;
    }

    printf(
"%d\n",temp);
    
if(temp==m)
        printf(
"Yes\n");
    
else
        printf(
"No\n");
    
return 0;
}

int main()
{

    
int num,num0;
//    long n;
    char s[500];
    
while(scanf("%d",&num)!=EOF)
    
{
      
/*num0=Test(num);
        printf("%d\n",num0);
        if(num0==num)
            printf("Yes\n");
        else
            printf("No\n");
*/

    
//    Numtostring(num,s);
    
//    puts(s);
    
//    StringTest(num); 
        NumberTest1(num);
    }

    
return 0;
}
 


    
posted on 2010-10-29 19:57 jince 阅读(616) 评论(0)  编辑 收藏 引用 所属分类: C++学习

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


哈哈哈哈哈哈