SHARE
TWEET

Untitled

Kernelovici Oct 12th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://www.pbinfo.ro/?pagina=probleme&id=946
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int reversed(int numar)
  8. {
  9.     int n = 0;
  10.     while(numar)
  11.     {
  12.         n += numar % 10;
  13.         n *= 10;
  14.         numar /= 10;
  15.     }
  16.     return n / 10;
  17. }
  18.  
  19. int bazaX(int numar, int baza)
  20. {
  21.     int n = 0;
  22.  
  23.     while(numar)
  24.     {
  25.         n += numar % baza;
  26.         n *= 10;
  27.         numar /= baza;
  28.     }
  29.     n /= 10;
  30.     return n;
  31. }
  32.  
  33. int bazaTen(char sir[])
  34. {
  35.     int n = 0;
  36.  
  37.     for(int i = 0; i < 6; i++)
  38.     {
  39.         n += sir[i] - '0';
  40.         n *= 2;
  41.     }
  42.     n /= 2;
  43.     return n;
  44. }
  45.  
  46. int main()
  47. {
  48.     int baza = 4;
  49.     char sir[6] = {'1', '0', '0', '0', '1', '1'}; //caz particular
  50.  
  51.     int ten = bazaTen(sir);
  52.     cout << "Baza 2: " << ten << endl;
  53.     int bazaN = bazaX(ten, baza);
  54.     cout << "Inainte: " << bazaN << endl;
  55.     cout << reversed(bazaN);
  56. }
RAW Paste Data
Top