Last active
January 2, 2016 13:18
-
-
Save agam/8308823 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cassert> | |
| #include <cmath> | |
| #include <cstdint> | |
| #include <cstdio> | |
| #include <cstdlib> | |
| #include <algorithm> | |
| #include <iomanip> | |
| #include <iostream> | |
| #include <limits> | |
| #include <string> | |
| #include <vector> | |
| #include <queue> | |
| #include <unordered_map> | |
| using namespace std; | |
| void InitializeBrailleData(unordered_map<string, char>* rep) { | |
| rep->insert(make_pair("O.....", 'A')); | |
| rep->insert(make_pair("O.O...", 'B')); | |
| rep->insert(make_pair("OO....", 'C')); | |
| rep->insert(make_pair("OO.O..", 'D')); | |
| rep->insert(make_pair("O..O..", 'E')); | |
| rep->insert(make_pair("OOO...", 'F')); | |
| rep->insert(make_pair("OOOO..", 'G')); | |
| rep->insert(make_pair("O.OO..", 'H')); | |
| rep->insert(make_pair(".OO...", 'I')); | |
| rep->insert(make_pair(".OOO..", 'J')); | |
| rep->insert(make_pair("O...O.", 'K')); | |
| rep->insert(make_pair("O.O.O.", 'L')); | |
| rep->insert(make_pair("OO..O.", 'M')); | |
| rep->insert(make_pair("OO.OO.", 'N')); | |
| rep->insert(make_pair("O..OO.", 'O')); | |
| rep->insert(make_pair("OOO.O.", 'P')); | |
| rep->insert(make_pair("OOOOO.", 'Q')); | |
| rep->insert(make_pair("O.OOO.", 'R')); | |
| rep->insert(make_pair(".OO.O.", 'S')); | |
| rep->insert(make_pair(".OOOO.", 'T')); | |
| rep->insert(make_pair("O...OO", 'U')); | |
| rep->insert(make_pair("O.O.OO", 'V')); | |
| rep->insert(make_pair(".OOO.O", 'W')); | |
| rep->insert(make_pair("OO..OO", 'X')); | |
| rep->insert(make_pair("OO.OOO", 'Y')); | |
| rep->insert(make_pair("O..OOO", 'Z')); | |
| }; | |
| void AddRepresentation(const string& line, vector<string>* representations) { | |
| for (int index = 0; index < line.length(); index += 3) { | |
| (*representations)[index / 3].push_back(line[index]); | |
| (*representations)[index / 3].push_back(line[index + 1]); | |
| assert((line[index + 2] == ' ') || (index + 2 == line.length())); | |
| } | |
| } | |
| int main() { | |
| unordered_map<string, char> braille_representation; | |
| InitializeBrailleData(&braille_representation); | |
| // Assume input is well formed. | |
| // This means we read three lines from standard input, | |
| // and each line's length is (3 * x - 1) | |
| string line1, line2, line3; | |
| getline(cin, line1); | |
| getline(cin, line2); | |
| getline(cin, line3); | |
| // Basic invariants | |
| assert(line1.length() == line2.length()); | |
| assert(line2.length() == line3.length()); | |
| assert((line1.length() + 1) % 3 == 0); | |
| // Get the input into our desired form | |
| vector<string> representations((line1.length() + 1) / 3); | |
| AddRepresentation(line1, &representations); | |
| AddRepresentation(line2, &representations); | |
| AddRepresentation(line3, &representations); | |
| for (const string& rep : representations) { | |
| cout << braille_representation[rep]; | |
| } | |
| cout << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment