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;

    }

          

     

  • 相关阅读:
    Gridview linkbutton click
    Linux Bluetooth编程 HCI层编程
    Google Android 开发工程师职位面试题
    Android下文件操作模式(含SDCard的读写)
    Android中悬浮窗口的实现原理和示例代码
    Android.mk的用法和基础
    Android.mk的用法和基础
    Linux Bluetooth编程 HCI层编程
    Android下文件操作模式(含SDCard的读写)
    init.rc 脚本语法学习
  • 原文地址:https://www.cnblogs.com/guohaoyu110/p/6323775.html
Copyright © 2011-2022 走看看