HackerRank 'Funny String' Solution

by Srikant Padala on June 25, 2016, 10:26 am


Explanation



Funny String Problem Statement

Video

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int t;
    cin >> t;
    string input, rev;
    while(t--) {
        cin >> input;
        rev = input;
        reverse(rev.begin(), rev.end());
        bool flag = true;
        for(int i=1; i < input.size(); i++) {
            if(abs(input[i] - input[i-1]) != abs(rev[i] - rev[i-1])) {
                flag = false;
                break;
            }
        }
        if(flag) cout << "Funny" << endl;
        else cout << "Not Funny" << endl;
    }
    return 0;
}

Coming Soon.