Click
Here to go back to the homepage.
Oktalni Solution:
#include <bits/stdc++.h>
using namespace std;
map<string, int> mapping = {
{"000", 0},
{"001", 1},
{"010", 2},
{"011", 3},
{"100", 4},
{"101", 5},
{"110", 6},
{"111", 7}
};
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
queue<char> q;
char c;
while(cin >> c){
q.push(c);
}
string s, result;
map<string, int>::iterator findr;
int toRemove = q.size() % 3;
if(toRemove){
int padding = 3 - toRemove;
while(padding--){
s.push_back('0');
}
while(toRemove--){
s.push_back(q.front());
q.pop();
}
findr = mapping.find(s);
cout << findr->second;
}
while(q.size()){
s.clear();
s.push_back(q.front());
q.pop();
s.push_back(q.front());
q.pop();
s.push_back(q.front());
q.pop();
findr = mapping.find(s);
cout << findr->second;
}
return 0;
}