Reverse a string and calculate ASCII difference

This a problem in HackerRank named "Funny String" where we are asked to output Funny if the ascii difference between the characters of the string and the reversed version of it is same. I mean if S is the string and R is the reversed version of it then |S[i]-S[i-1]|=|R[i]-R[i-1]|, for i=0 --> N-1 and Not Funny otherwise. I have done the coding but it's failing in some test cases, what's wrong in it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  #include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int t;
	string s,tmp,sr;
	cin>>t;
	while(t--){
	int f=0;
	cin>>s;
	tmp=s;
	reverse(tmp.begin(),tmp.end());
	sr=tmp;
	for(int i=1;i<sr.size();i++){
	
	if(abs(s[i]-s[i-1])==abs(sr[i]-sr[i-1]))
		f=1;
	else 
		f=0;
	}
	if(f==1)
	   cout<<"Funny\n";
	else
	   cout<<"Not Funny\n";
	}

return 0;
}
Is funny IF difference for each pair is same.
In other words: is not funny, IF at least one pair differs.

Lets assume that is funny (f=1).
If a pair is same, there is nothing to do.
If a pair is not same, set f=0.

The f==1 after all pairs only if no pair was different.
Topic archived. No new replies allowed.