第八题
class Solution { public: int myAtoi(string str) { int i = 0; long sum = 0; int sign = 1; while(str[i] == ' ')i++; if (str[i] == '-'|| str[i] == '+') { if(str[i] == '-') sign = -1; i++; } while(str[i]<='9' && str[i]>='0') { if(sum>=INT_MAX) break; sum = sum * 10 + str[i++] - '0'; } sum*=sign; if(sum>=INT_MAX)return INT_MAX; if(sum<=INT_MIN)return INT_MIN; return sum; } };