函数题:编写函数将数字串转换为整数
要求实现一个函数,把一个数字字符串转换为一个整数。
### 函数接口定义:
c++
int s2i(string s);
其中 s 是用户传入的参数,存放待转换为整数的数字串。
### 裁判测试程序样例:
c++
#include<iostream>
#include<string>
using namespace std;
int main(){
string s,t;
while(cin>>s>>t) {
cout<<s2i(s)+s2i(t)<<endl;
}
return 0;
}
### 输入样例:
in
1234 56789
### 输出样例:
out
58023
答案:若无答案欢迎评论
### 函数接口定义:
c++
int s2i(string s);
其中 s 是用户传入的参数,存放待转换为整数的数字串。
### 裁判测试程序样例:
c++
#include<iostream>
#include<string>
using namespace std;
int main(){
string s,t;
while(cin>>s>>t) {
cout<<s2i(s)+s2i(t)<<endl;
}
return 0;
}
### 输入样例:
in
1234 56789
### 输出样例:
out
58023
答案:若无答案欢迎评论