现在的位置: 首页 > 综合 > 正文

Nyoj 844 A+B Problem[字符串逆序]

2017年10月13日 ⁄ 综合 ⁄ 共 596字 ⁄ 字号 评论关闭

题目连接:点击打开链接

网上啥啥都特别乱,自己看了点,直接自己写了个被称为原地逆序。

void ABBA(char a[])
{
    int left=0,right=strlen(a)-1;
    while(left<=right)
    {
        swap(a[left],a[right]);
        left++;
        right--;
    }
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=15;
void ABBA(char a[])
{
    int left=0,right=strlen(a)-1;
    while(left<=right)
    {
        swap(a[left],a[right]);
        left++;
        right--;
    }
}
int main()
{
    char a[N],b[N];
    while(~scanf("%s%s",a,b))
    {
        int alen=strlen(a),blen=strlen(b);
        if(alen==1&&a[0]=='0'&&blen==1&&b[0]=='0') return 0;
        ABBA(a);ABBA(b);
        printf("%d\n",atoi(a)+atoi(b));
    }
}

这里补充两个函数:

atoi();点击打开链接

atif();点击打开链接

很是受用。

抱歉!评论已关闭.