题解 | #a+b#

a+b

https://www.nowcoder.com/practice/4c39c984ea3848b48e111b8e71ec1dd4

#include <iostream>
#include<vector>
using namespace std;

int main() {
    string a,b;
    while(cin>>a>>b)
    {
        vector<int>v;
        int temp=0;
        int m=a.length(),n=b.length();
        for(int i=0;i<m||i<n;i++)
        {
            if(i<m)temp+=a[m-1-i]-'0';
            if(i<n)temp+=b[n-i-1]-'0';
            v.push_back(temp%10);
            temp=temp/10;
        }
        if(temp!=0)v.push_back(temp);
        for(int i=v.size()-1;i>=0;i--)
        cout<<v[i];
        cout<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

在debug的柠檬精很迷人:好消息:现在HR挑三拣四 15年后 HR跪着求要简历 坏消息:被挑的是这代人,到时候求人的也是这代人。真好。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务