Below solutions gives correct output if run on other editor but fails here


#1

Input: 5121478262 8070067M75 X199R 547 8C0A11 93I630 4P4071 029W433619 M3 5 14703818 776366059B9O43393

Output: 826510966
Expected: 2147483647

It gave expected output on other editor but not here.

int atoi(const char* A) {
int i,s=0;
for(i=0;i<strlen(A);i++) {
if(A[i]>=‘0’ && A[i]<=‘9’) {
if(s>(INT_MAX)/10)
return INT_MAX;
if(s<(INT_MIN)/10)
return INT_MIN;
s=s*10+(A[i]-‘0’);
} else if(s && !(A[i]>=‘0’ && A[i]<=‘9’)) {
if(s>(INT_MAX)/10)
return INT_MAX;
if(s<(INT_MIN)/10)
return INT_MIN;
break;
}
}
return s;
}