pratiyush7

Untitled

Dec 2nd, 2021
611
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Pratiyush Mishra
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. string uppercase(string s)
  7. {
  8.   string ans = "";
  9.   for (char c : s)
  10.   {
  11.     char d;
  12.     if (c >= 'A' && c <= 'Z')
  13.       d = c;
  14.     else
  15.       d = char(c  - 'a' + 'A');
  16.     ans += d;
  17.   }
  18.   return ans;
  19. }
  20.  
  21. int countSetBits(char c)
  22. {
  23.   int n = c;
  24.   int count = 0;
  25.   while (n) {
  26.     count += n & 1;
  27.     n >>= 1;
  28.   }
  29.   return count;
  30. }
  31.  
  32. void decToOctal(int n)
  33. {
  34.   int octalNum[100];
  35.   int i = 0;
  36.   while (n != 0) {
  37.     octalNum[i] = n % 8;
  38.     n = n / 8;
  39.     i++;
  40.   }
  41.   string ans = "";
  42.   for (int j = i - 1; j >= 0; j--)
  43.     cout << octalNum[j];
  44. }
  45.  
  46. void mainSolve()
  47. {
  48.   string s;
  49.   cin >> s;
  50.   s = uppercase(s);
  51.   int shift = 0;
  52.   for (char c : s)
  53.     shift += countSetBits(c);
  54.   decToOctal(shift);
  55.   string ans = "";
  56.   for (char c : s)
  57.   {
  58.     int sft = (c - 'A' + shift) % 26;
  59.     char d = char(sft + 'A');
  60.     cout << d;
  61.   }
  62.   cout << endl;
  63. }
  64.  
  65. int main()
  66. {
  67.   int t = 1;
  68.   while (t--)
  69.   {
  70.     mainSolve();
  71.   }
  72.   return 0;
  73. }
  74.  
RAW Paste Data