文章

10

粉丝

179

获赞

5

访问

27.2k

头像
运用字符串函数stoi直接转为整数再相加
P1003 兰州大学机试题
发布于2023年2月11日 09:41
阅读数 2.8k

#include <bits/stdc++.h>
using namespace std; 
typedef long long ll;
const int INF=1e9;
int n=0;
string a,b;
int sum=0;
vector<int> ve;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    while(cin>>a>>b){ //输入两个字符串代替翻转数
        
        reverse(a.begin(),a.end());//获得原数
        reverse(b.begin(),b.end());
        sum+=stoi(a)+stoi(b);//将字符串直接转换为整数并且相加
        cout<<sum<<endl;
        sum=0;
    }
    
    
        
     return 0;
 }
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发