zoukankan      html  css  js  c++  java
  • 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;

    }

          

     

  • 相关阅读:
    eclipse下切换svn用户
    Netty实现服务端客户端长连接通讯及心跳检测
    Spring Batch系列总括(转载)
    SQL中的Null深入研究分析
    MySQL报错“1366
    Memcache学习php完整一例
    Memcache学习笔记
    递归和迭代区别
    解决textarea 输出有空格问题
    解决mysql安装出现error Nr.1045问题
  • 原文地址:https://www.cnblogs.com/guohaoyu110/p/6323775.html
Copyright © 2011-2022 走看看