Skip to content

Instantly share code, notes, and snippets.

@vectorijk
Created November 5, 2014 08:53
Show Gist options
  • Save vectorijk/6161a0626ae210563499 to your computer and use it in GitHub Desktop.
Save vectorijk/6161a0626ae210563499 to your computer and use it in GitHub Desktop.
ICPC PacNW 12 Problem L Tongues
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
char s[150];
char vow[] = "aiyeou";
char con[] = "bkxznhdcwgpvjqtsrlmf";
map<char, int> v;
map<char, int> c;
for(int i = 0; vow[i] != '\0'; i++){
v[vow[i]] = i;
}
for(int i = 0; con[i] != '\0'; i++){
c[con[i]] = i;
}
while(gets(s)){
for(int i = 0; s[i] != '\0';i++){
if(s[i] >= 'a' && s[i] <= 'z'){
if ( s[i] == 'a' || s[i] == 'e' || s[i] == 'i'
|| s[i] == 'o' || s[i] == 'u' || s[i] == 'y'){
cout << vow[ (v[s[i]] + 3) % 6 ];
}
else{
cout << con[ (c[s[i]] + 10) % 20 ];
}
}
else if (s[i] >= 'A' && s[i] <= 'Z'){
if ( s[i] == 'A' || s[i] == 'E' || s[i] == 'I'
|| s[i] == 'O' || s[i] == 'U' || s[i] == 'Y'){
cout << (char)(vow[ (v[s[i] + ('a' - 'A')] + 3) % 6 ] - ('a' - 'A'));
}
else{
cout << (char)(con[ (c[s[i] + ('a' - 'A')] + 10) % 20 ] - ('a' - 'A'));
}
}
else{
cout << s[i];
}
}
cout << endl;
}
return 0;
}
#include <cstdio>
using namespace std ;
const char *vowels = "aiyeou" ;
const char *cons = "bkxznhdcwgpvjqtsrlmf" ;
char remap[128] ;
int main(int argc, char *argv[]) {
for (int i=0; i<128; i++)
remap[i] = i ;
for (const char *p=vowels; p[3]; p++) {
remap[(int)*p] = p[3] ;
remap[(int)p[3]] = *p ;
}
for (const char *p=cons; p[10]; p++) {
remap[(int)*p] = p[10] ;
remap[(int)p[10]] = *p ;
}
for (char i='A'; i<='Z'; i++)
remap[(int)i] = 'A'+remap['a'+i-'A']-'a' ;
int c ;
while ((c=getchar()) != EOF)
putchar(remap[c]) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment