-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfunny_string.cpp
More file actions
58 lines (48 loc) · 901 Bytes
/
funny_string.cpp
File metadata and controls
58 lines (48 loc) · 901 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
string funny_string(string str){
string reverse = "";
int k=0;
int diff[str.length()];
int diff_rev[str.length()];
int c=0;
for(int i=str.length()-1;i>=0;i--){
reverse+=str[i];
}
//checking absolute difference of simple string
for(int i=0;i<str.length()-1;i++){
diff[k] = abs(str[i] - str[i+1]);
k++;
}
//checking absolute difference of reverse string
for(int i=0;i<reverse.length()-1;i++){
diff_rev[c] = abs(reverse[i] - reverse[i+1]);
c++;
}
int count=0;
for(int i=0;i<k;i++){
if(diff[i] == diff_rev[i])
count++;
}
if(count==k)
return "Funny";
else
return "Not Funny";
}
int main()
{ int test;
cin>>test;
string str;
string res[test];
int k=0;
for(int i=0;i<test;i++){
cin>>str;
res[k] = funny_string(str);
k++;
}
//display
for(int i=0;i<k;i++)
cout<<res[i]<<"\n";
}