class Solution {
public:
int StrToInt(string str) {
int sum = 0;
int data;
if(str.empty())
return 0;
int i = 0;
if(str[i] == '+'||str[i] == '-')
{
if(str[2]==NULL)
return 0;
else
{
if(str[2]>'9'||str[2]<'1')
return 0;
else
{
int i = 3;
while(str[i]!=NULL)
{
if(str[i]>'9'||str[i]<'0')
return 0;
//break;
i++;
}
}
}
}
else
{
if(str[i] == '0')
return 0;
else
{
while(str[i]!=NULL)
{
if(str[i]>'9'||str[i]<'0')
return 0;
//break;
i++;
}
}
}
i = 0;
if(str[0]=='-')
{
data = -1;
i++;
}
else
{
if(str[0]=='+')
{
data = 1;
i++;
}
}
while(str[i] != NULL)
{
sum = sum*10 + (str[i]-'0');
i++;
}
return sum*data;
}
};