Char* ITOA (intNumChar*STR,intRadix) {/*Index Table*/ Charindex[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Unsigned unum;/*Intermediate Variables*/ intI=0, J,k; /*determine the value of the Unum*/ if(radix==Ten&&num<0)/*decimal Negative*/{Unum= (unsigned)-num; Str[i++]='-'; } Elseunum= (unsigned) num;/*Other conditions*/ /*Conversion*/ Do{str[i++]=index[unum%(unsigned) radix]; Unum/=Radix; } while(Unum); Str[i]=' /'; /*Reverse*/ if(str[0]=='-') K=1;/*decimal Negative*/ Elsek=0; Chartemp; for(J=k;j<= (i1)/2; j + +) {Temp=Str[j]; STR[J]=str[i-1+k-J]; Str[i-1+k-j]=temp; } returnstr;}
classSolution { Public: BOOLIsDigit (Charc) { if(c >= -&& C <= $) return true; Else return false; } intAtoistringstr) { Long LongAns =0, res=1; BOOLFlag =false; CharC; for(intI=0; i < str.size (); i++) {C=Str[i]; if(!flag && (c==' '|| c=='\ t'|| c=='\ r'|| c=='\ n') )Continue; if(!flag && (c=='+'|| c=='-') ){ if(c=='-') Res =-1; Flag=true; Continue; } if(!flag &&IsDigit (c)) {Flag=true; } if(!isdigit (c)) Break; Ans= ans *Ten+ (C-'0'); //cout<<ans<< ' <<c<<endl; if(Ans >Int_max) { Break; }} ans*=Res; if(Ans > int_max) ans =Int_max; Else if(Ans < int_min) ans =int_min; return(int) ans; }};
Atoi&itoa