Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string toBin(unsigned int n) {
- string result = "";
- if (n / 2 != 0) {
- result += toBin(n / 2);
- }
- if (n % 2 == 0) result += "0";
- else result += "1";
- return result;
- }
- string to8Bit(string bin) {
- string result = "";
- for (int i = 0; i < 8 - bin.length(); i++) {
- result += "0";
- }
- return result + bin;
- }
- int toDec(string number) {
- int result = 0, pow = 1;
- for (int i = number.length() - 1; i >= 0; --i, pow <<= 1)
- result += (number[i] - '0') * pow;
- return result;
- }
- string negation(string bin) {
- string result = "";
- for (int i = 0; i < bin.length(); i++) {
- if (bin[i] == '1') result += "0";
- else result += "1";
- }
- return result;
- }
- int main() {
- int n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- string text;
- cin >> text;
- for (int j = 0; j < text.length(); j++) {
- char c = text[j];
- char baseChar = 'a';
- if (c == toupper(c)) {
- baseChar = 'A';
- }
- cout << (char)(toDec(negation(to8Bit(toBin(c)))) % 26 + baseChar);
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement