题解 | #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可以处理负号,没必要判断
点赞 回复 分享
发布于 2025-03-24 15:34 河南

相关推荐

2025-12-15 14:25
云南大学 Java
lei22:入职可能会看学信网,最好别伪装,这个简历找实习肯定是够的,肯定会有收 28 届实习生的公司的,多投就行
点赞 评论 收藏
分享
评论
6
1
分享

创作者周榜

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