fork download
  1. #include <iostream>
  2. using namespace std;
  3. class Solution{
  4. public:
  5. /*You are required to complete this method */
  6. // create a function to check if the character ids numeric or not
  7. bool isnumeric(char x){
  8. // check the condition for the numeric
  9. return (x>='0' && x<='9')? true:false;
  10. }
  11. int atoi(string s) {
  12. int n=s.size();
  13. if (s==" "){
  14. return 0;
  15. }
  16. int res=0;
  17. int sign=1;
  18. int i=0;
  19. // Base condition for the given program
  20. if(s[0]=='-'){
  21. sign=-1;
  22. i++;
  23. }
  24. // Run the loop for the given eqation
  25. for(;i<n;++i){
  26. if(isnumeric(s[i])==false){
  27. return -1;
  28. // res=res*10+s[i] -'0';
  29. }
  30. res=res*10+s[i] -'0';
  31.  
  32.  
  33. }
  34.  
  35. return sign*res;
  36. }
  37.  
  38. };
  39. int main() {
  40. // your code goes here
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty