Skip to content

Instantly share code, notes, and snippets.

@logicmd
Created July 17, 2012 06:22
Show Gist options
  • Save logicmd/3127573 to your computer and use it in GitHub Desktop.
Save logicmd/3127573 to your computer and use it in GitHub Desktop.
Problem A. Speaking in Tongues
/*************************************************************************
Author: logicmd
Created Time: 2012/7/16 19:55:16
File Name: Problem A. Speaking in Tongues.cpp
Description:
This problem is so damn. The problem description gives participant a
one to one mapping relation, and it just letter 'z'.
So the best solution is not to built a hashmap yourself, but to build a
map manually brutely. WTF
************************************************************************/
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <utility>
#include <algorithm>
#define MAX 30
#define MAXSIZE 100
using namespace std;
map<char, char> buildMapper()
{
// 'z' -> 'q'
string src = \
"z ejp mysljylc kd kxveddknmc re jsicpdrysi"
"rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"
"de kr kd eoya kw aej tysr re ujdr lkgc jv y e q";
string dst = \
"q our language is impossible to understand"
"there are twenty six factorial possibilities"
"so it is okay if you want to just give up a o z";
map<char, char> mapper;
for(int i = 0; i < src.length(); i++ )
{
mapper.insert(make_pair(src[i], dst[i]));
}
return mapper;
}
string decode(map<char, char> mapper, string src)
{
string dst;
for(int i = 0; i < src.length(); i++)
{
dst.push_back(mapper.find(src[i])->second);
}
return dst;
}
int main()
{
string inputs[MAX + 1];
int n;
cin >> n;
for (int i = 0; i < n + 1; i ++)
{
getline(cin, inputs[i]);
}
map<char, char> mapper = buildMapper();
for (int i = 1; i < n + 1; i ++)
{
cout << "Case #" << i << ": ";
cout << decode(mapper, inputs[i]) << endl;
}
system("PAUSE");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment