AABELLUS

zhui

Feb 21st, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <cstring>
  3. #define DIG "0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ"
  4. using namespace std;
  5.  
  6. int Atoi(char *s, int p){
  7.     int i, a, digit[256] = {0};
  8.     for(i = 0; DIG[i]; i++)
  9.         digit[DIG[i]] = i;
  10.     for(i = a = 0; s[i]; i++)
  11.         a = a * p + digit[s[i]];
  12.     return a;
  13. }
  14.  
  15. void Itoa(int a, int p, char *s) {
  16.    static int i = 0, n;
  17.    if (a) {
  18.       ++i;
  19.       Itoa(a / p, p, s);
  20.       s[n - i--] = DIG[a % p];
  21.    }
  22.    else
  23.       s[n = i] = '\0';
  24. }
  25.  
  26. int main(){
  27.    char s[1024] = "29234652";
  28.    Itoa(Atoi(s, 10), 36, s);
  29.    cout << s << endl;
  30.    return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment