class Solution {
public:
    int StrToInt(string str) {
        int idx = 0;
        int flag = 1;
        if(str[0] > '9' || str[0] < '0'){
            idx ++;
            if(str[0] == '-'){
                flag -= 2;
            }else if(str[0] != '+'){
                return 0;
            }
        }
        int val = 0;
        while(idx < str.size()){
            if(str[idx] > '9' || str[idx] < '0') return 0;
            val = val*10 + (str[idx] - '0');
            idx ++;
        }
        return val * flag;
    }
};