ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-08-08 17:37:11  阅读:372  来源: 互联网

标签:10 int reversed 第七场 多校 number 牛客 sumb suma


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有