Julius Cipher is a type of cipher which relates all the lowercase alphabets to their numerical position in the alphabet, i.e., the value of a is 1, the value of b is 2, the value of z is 26 and similarly for the rest of them.
Little Chandan is obsessed with this Cipher and he keeps converting every single string he gets, to the final value one gets after the multiplication of the Julius Cipher values of a string. Arjit is fed up of Chandan's silly activities, so he decides to at least restrict Chandan's bad habits.
So, he asks Chandan not to touch any string which is a palindrome, otherwise, he is allowed to find the product of the Julius Cipher values of the string.
Example:
Input: s = "zazaz"
Output: Palindrome
Approach
C++
#include <bits/stdc++.h>using namespace std;bool ispalindrome(string s){long long n = s.size();for (long long i = 0; i < n / 2; i++){if (s[i] != s[n - i - 1])return false;}return true;}int main(){string s = "zazaz";if (ispalindrome(s))cout << "Palindrome\n";else{long long ans = 1, n = s.size();for (long long i = 0; i < n; i++)ans = ans * (s[i] - 'a' + 1);cout << ans << "\n";}return 0;}
No comments:
Post a Comment