duonglee

PTIT124J - Chuyển đổi hệ cơ số (bản dễ)

Jul 12th, 2017
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6.     //IN;
  7.     string bin;
  8.     cin>>bin;
  9.     while (bin.length()%3!=0)
  10.     {
  11.         bin = '0'+bin;
  12.     }
  13.     //OUT;
  14.     string find;
  15.     for (int i=0; i<bin.length(); i+=3)
  16.     {
  17.         find="";
  18.         for (int j=i; j<i+3; j++) {
  19.             find+=bin[j];
  20.         }
  21.         if (find=="000") cout<<"0";
  22.         if (find=="001") cout<<"1";
  23.         if (find=="010") cout<<"2";
  24.         if (find=="011") cout<<"3";
  25.         if (find=="100") cout<<"4";
  26.         if (find=="101") cout<<"5";
  27.         if (find=="110") cout<<"6";
  28.         if (find=="111") cout<<"7";
  29.     }
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment