题解 | #A+B#用stoi 做更快一点

A+B

https://www.nowcoder.com/practice/b183eac8dfba4de99d47c1ca4ce9571f

#include <iostream>
using namespace std;

int func(string s)
{
    string temp;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=','&&s[i]!='-')
        {
            temp+=s[i];
        }
    }
    return s[0]=='-'?-stoi(temp):stoi(temp);
}

int main() {
    string a,b;
    while(cin>>a>>b)
    {
        cout<<func(a)+func(b)<<endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论
stoi可以处理负号,没必要判断
点赞 回复 分享
发布于 03-24 15:34 河南

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
评论
6
1
分享

创作者周榜

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