Showing posts with label convert octal-decimal. Show all posts
Showing posts with label convert octal-decimal. Show all posts

Sunday, April 9, 2017

Uri 1832 - EBCDIC

#include<bits/stdc++.h>
using namespace std;

int octal_to_decimal(int oc){
  int d = 0, i = 0, rem;
    while (oc != 0)
    {
        rem = oc % 10;
        oc /= 10;
        d += rem * pow(8, i);
        ++i;
    }
    return d;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long n,k = 0;
    string s;
        int Tableebc2Asc[256] =
    {
            32,  32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 91, 46, 60, 40, 43, 33,
            38, 32, 32, 32, 32, 32, 32, 32,
            32, 32, 93, 36, 42, 41, 59, 94,
            45, 47, 32, 32, 32, 32, 32, 32,
            32, 32,124, 44, 37, 95, 62, 63,
            32, 32, 32, 32, 32, 32,238,160,
            161, 96, 58, 35, 64, 39, 61, 34,
            230, 97, 98, 99,100,101,102,103,
            104,105,164,165,228,163,229,168,
            169,106,107,108,109,110,111,112,
            113,114,170,171,172,173,174,175,
            239,126,115,116,117,118,119,120,
            121,122,224,225,226,227,166,162,
            236,235,167,232,237,233,231,234,
            158,128,129,150,132,133,148,131,
            123, 65, 66, 67, 68, 69, 70, 71,
            72, 73,149,136,137,138,139,140,
            125, 74, 75, 76, 77, 78, 79, 80,
            81, 82,141,142,143,159,144,145,
            92, 32, 83, 84, 85, 86, 87, 88,
            89, 90,146,147,134,130,156,155,
            48, 49, 50, 51, 52, 53, 54, 55,
            56, 57,135,152,157,153,151, 32
    };
    while(getline(cin,s)){
            vector < string > ans;
            stringstream stl(s);
            string take;
            while (stl >> take)
            ans.push_back(take);

            for(int i = 0 ; i < ans.size() ; i++){
            stringstream str2(ans[i]);
            int p = 0;
            str2 >> p;
            unsigned char d = octal_to_decimal(p);
            (i != ans.size()-1)?printf("%c",Tableebc2Asc[d]) : printf("%c\n",Tableebc2Asc[d]);
            }
    }
    return 0;
}