Question d’entretien chez Microsoft

Implement a function that turns a string into a number with sign.

Réponse à la question d'entretien

Utilisateur anonyme

12 déc. 2012

Here's a C# solution: int strToInt( string str){ int i = 1, num = 0, len = str.Length(); bool isNeg = false; if( str[0] == '-') { isNeg = true; } while( i < len){ num*=10 num+= (str[i++] - '0'); } if ( isNeg ) { num *= -1; } return num; }