Monday, January 20, 2014

codechef TOTR - "tourist translations" solution

codechef TOTR - "tourist translations" :  http://www.codechef.com/problems/TOTR

codechef TOTR - "tourist translations" solution: http://ideone.com/FwN23v

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
int t, m1[30];
char m[30], s[105];
scanf("%d%s", &t, m);
for(int i=0; i<strlen(m); i++) m1[i]=m[i]-'a';
for(int i=0; i<t; i++) {
scanf("%s", s);
for(int j=0; j<strlen(s); j++) {
if(s[j]>='A' && s[j]<='Z') {
printf("%c", m1[s[j]-65]+65);
}
else if(s[j]>='a' && s[j]<='z') {
printf("%c", m1[s[j]-97]+97);
}
else if(s[j]=='_') printf(" ");
else printf("%c", s[j]);
}
printf("\n");
}
return 0;
}

note: imho, here is only imp thing is just char conversions, look at the ascii table to understand the logic behind number 65 for capital letters and 97 for lowercase letters

No comments:

Post a Comment