2019牛客暑期多校训练营(第七场)J A+B problem

4 篇文章 0 订阅

J A+B problem

链接:https://ac.nowcoder.com/acm/contest/887/J
来源:牛客网

题目描述

Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. And all the leading zeros are omitted.
For example: the reversed number of 1234 is 4321. The reversed number of 1000 is 1.

We define reversed number of as . Given you two positive integers and , you need to calculate the reversed sum: .

输入描述:

The first line of the input gives the number of test cases, T (T≤300). test cases follow.

For each test case, the only line contains two positive integers: and . ( 1≤A,B≤231-1 )

输出描述:

For each test case, output a single line indicates the reversed sum.

示例1

输入

3
12 1
101 9
991 1

输出

22
11
2

题意

对数字 A、B 分别求反,然后相加,再求反

分析

A、B 的范围在 int 内,所以直接求解即可

代码

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll; 

char a[15],b[15];
int main(){
   int t;
   cin>>t;
   while(t--){
      scanf("%s%s",&a,&b);
      ll x=strlen(a);
      ll y=strlen(b);
      ll suma=0,sumb=0;
      for(int i=x-1;i>=0;i--){
            int w=a[i]-'0';
            suma=suma*10+w;
         }
      for(int i=y-1;i>=0;i--){
            int w=b[i]-'0';
            sumb=sumb*10+w;
      }
      x=suma+sumb;
      y=0;
      for(;x!=0;x/=10){
        y=y*10+x%10;
      }
      cout<<y<<endl;
   }       
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值