实现函数 StringToInt 。
函数的功能为将字符串转化为整数
提示:仔细思考所有可能的输入情况。这个问题没有给出输入的限制,你需要自己考虑所有可能的情况。
本关任务:编写一个能计算数组平均值和最大值的小程序。
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M 热度指数:27326
本题知识点: 字符串
测试:
输入
“2020”
返回值
2020
输入
“ 2020”
返回值
2020
输入
“+2020”
返回值
2020
需要填空的代码
// #include <limits.h>
#include <iostream>
using namespace std;
/*
Write a function to convert a number string into a corresponding value
TestCase
2020
2020
2021
2020
2020
2021
+2020
+2020
2021
-2020
-2020
-2019
*/
class Solution {
public:
int stringToInt(const char *str