题解 | #数字颠倒#

数字颠倒

http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe

#include "stdio.h"

int main(void)
{
    int num = 0;

    while(scanf("%d",&num) !=EOF)
    {
        char *str = (char *)calloc(15,sizeof(char));
        sprintf(str,"%d",num);/*将整型数据转换成字符串*/
        int j =strlen(str) - 1;
        int i = 0;
        int tmp = 0;
        while(i < j)        /*字符串反转*/
        {
            tmp = str[i];
            str[i] = str[j];
            str[j] = tmp;
            i++;
            j--;
        }
        printf("%s\n",str); /*输出*/
        free(str);
    }
    return 0;
}
全部评论

相关推荐

03-07 13:32
门头沟学院 C++
未来可欺a:读研吧,这简历只适合学历高的,本科大概率只能干开发,你这个简历开发不匹配,算法和深度学习的话学历又不够
点赞 评论 收藏
分享
大摆哥:刚好要做个聊天软件,直接让你帮他干活了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务