• POJ 1504 Adding Reversed Numbers


    /*Sample Input

     

     3

     24 1

     4358 754

     305 

     

     Sample Output

     

     34

     1998

     */

    值得总结的几点就是:

    1、atoi函数将字符串转化为整型数字(类似于强制转换)

    2、sprintf函数的用法,比如sprintf(res,"%d",i+j);

    3、这种将字符串逆置的方法应该是最简洁的

    #include<iostream>

    #include <stdio.h>

    #include <stdlib.h>

    #include <string.h>

    using namespace std;

    void toreverse(char ch[])

    {

        int i;

        int n=(int)strlen(ch);

        char temp;

        for(i=0;i<n/2;i++)

        {

            temp=ch[i];

            ch[i]=ch[n-1-i];

            ch[n-1-i]=temp;

        }

    }

     

    int main()

    {

        int N,i,j;

        char res[10],a[10],b[10];

        cin>>N;

        while(N--)

        {

            cin>>a>>b;

            toreverse(a);

            toreverse(b);

            i = atoi(a);//atoi函数将字符串转化为数字(int

             j = atoi(b);

            sprintf(res,"%d",i+j);

            toreverse(res);

            printf("%d ",atoi((char *)res));

        }

        return 0;

    }

          

     

  • 相关阅读:
    面试
    无中生有
    数字称王-0-10000,
    数组排序
    uiview 阴影
    TTTAtibutedlabel again
    vim配置python编程环境及YouCompleteMe的安装教程
    centos7下vim8.1的编译安装教程
    centos7下误执行chmod -R 777 /后的权限修复方法
    如何用浏览器在线查看.ipynb文件
  • 原文地址:https://www.cnblogs.com/guohaoyu110/p/6323775.html
Copyright © 2020-2023  润新知