题解 | #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 河南

相关推荐

如题
投递阿里巴巴集团等公司10个岗位 >
点赞 评论 收藏
分享
04-28 22:33
已编辑
门头沟学院 C++
点赞 评论 收藏
分享
05-29 20:34
门头沟学院 C++
KarlAllen:得做好直接春招的准备。学历差的话,一是面试要求会比学历好的严格不少,二是就算面试通过了也会被排序。总之暑期和秋招对于学历差的就是及其不友好
点赞 评论 收藏
分享
评论
6
1
分享

创作者周榜

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