Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<iostream>
- using namespace std;
- int toLower(int code){
- return code + 32;
- };
- int isCapital(int code) {
- return (code >= 65 && code <= 90);
- };
- int toUpper(int code) {
- return code - 32;
- };
- bool isAlpha(int code){
- return (isCapital(code) || (code >= 97 && code <= 122));
- };
- tuple<int, int> processChar(int code) {
- tuple<int, int> returnVal;
- bool const alpha = isAlpha(code);
- if(alpha){
- bool const capital = isCapital(code);
- if(capital) {
- int const lowerCaseChar = toLower(code);
- returnVal = make_tuple(1, lowerCaseChar);
- } else returnVal = make_tuple(0, code);
- } else returnVal = make_tuple(-1, code);
- return returnVal;
- };
- void translate(string alphabet, string sen){
- char transCode;
- for (auto i = sen.begin(); i != sen.end(); i++) {
- int code = (*i);
- tuple<int, int> charInfo = processChar(code);
- int alphaCheck, transformCode;
- tie(alphaCheck, transformCode) = charInfo;
- if(alphaCheck >= 0){
- int idx = transformCode - 'a';
- transCode = alphabet[idx];
- if(alphaCheck == 1) transCode -= 32;
- } else if(transformCode == 95){
- transCode = ' ';
- }else transCode = transformCode;
- cout << transCode;
- }
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(NULL);
- int tc;
- cin >> tc;
- string balpha;// = "qwertyuiopasdfghjklzxcvbnm"; //= "zabcdefghijklmnopqrstuvwxy";
- cin >> balpha;
- while (tc != 0) {
- string sen;
- cin >> sen;
- translate(balpha, sen);
- cout << "\n";
- tc--;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment