其他分享
首页 > 其他分享> > 2019牛客暑期多校训练营(第七场)J A+B problem

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

作者:互联网

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;
   }       
}

标签:10,int,reversed,第七场,多校,number,牛客,sumb,suma
来源: https://blog.csdn.net/weixin_42664622/article/details/98878292