Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string toBin(unsigned int n) {
  7. string result = "";
  8.  
  9. if (n / 2 != 0) {
  10. result += toBin(n / 2);
  11. }
  12.  
  13. if (n % 2 == 0) result += "0";
  14. else result += "1";
  15.  
  16. return result;
  17. }
  18.  
  19. string to8Bit(string bin) {
  20. string result = "";
  21. for (int i = 0; i < 8 - bin.length(); i++) {
  22. result += "0";
  23. }
  24. return result + bin;
  25. }
  26.  
  27. int toDec(string number) {
  28. int result = 0, pow = 1;
  29. for (int i = number.length() - 1; i >= 0; --i, pow <<= 1)
  30. result += (number[i] - '0') * pow;
  31.  
  32. return result;
  33. }
  34.  
  35. string negation(string bin) {
  36. string result = "";
  37.  
  38. for (int i = 0; i < bin.length(); i++) {
  39. if (bin[i] == '1') result += "0";
  40. else result += "1";
  41. }
  42.  
  43. return result;
  44. }
  45.  
  46. int main() {
  47. int n;
  48. cin >> n;
  49.  
  50. for (int i = 0; i < n; i++) {
  51. string text;
  52. cin >> text;
  53.  
  54. for (int j = 0; j < text.length(); j++) {
  55. char c = text[j];
  56. char baseChar = 'a';
  57.  
  58. if (c == toupper(c)) {
  59. baseChar = 'A';
  60. }
  61.  
  62. cout << (char)(toDec(negation(to8Bit(toBin(c)))) % 26 + baseChar);
  63. }
  64.  
  65. cout << endl;
  66. }
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement