- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunnyString.java
More file actions
Latest commit
74 lines (59 loc) · 2.19 KB
/
Copy pathFunnyString.java
File metadata and controls
74 lines (59 loc) · 2.19 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Suppose you have some string SS having length NN that is indexed from 00 to N−1N−1. You also have some string RR that is the reverse of string SS. SS is funny if the condition | S[j]−S[j−1] |=| R[j]−R[j−1] || S[j]−S[j−1] |=| R[j]−R[j−1] | is true for every jj from 11 to N−1N−1.
Note: For some string SS, S[j]S[j] denotes the ASCII value of the jthjth zero-indexed character in SS. The absolute value of some integer xx is written as | x || x |.
Input Format
The first line contains an integer, TT (the number of test cases).
The TT subsequent lines each contain a string, where the ithith line is string SiSi.
Constraints
1≤T≤101≤T≤10
0≤i≤T−10≤i≤T−1
2≤length of Si≤100002≤length of Si≤10000
Output Format
For each SiSi, print Funny or Not Funny on a new line.
*/
importjava.io.*;
importjava.util.*;
importjava.text.*;
importjava.math.*;
importjava.util.regex.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
Scannerscan = newScanner(System.in);
intt= scan.nextInt();
for(inti=1;i<=t;i++)
{
Strings= scan.next();
intk=s.length();
intl=k-1;
intflag=0;
for(intj=0;j<k;j++)
{
if(j+1<=k-1&&l-1>=0)
{
intm = (int)s.charAt(j);
intn=(int)s.charAt(j+1);
intdiff1=Math.abs(n-m);
// System.out.println(diff1);
intp=s.charAt(l);
intq=s.charAt(l-1);
intdiff2=Math.abs(q-p);
// System.out.println(diff2);
if(diff1!=diff2)
{
// System.out.println("yes");
flag=1;
}
}
l--;
}
if(flag==0)
{
System.out.println("Funny");
}
else
{
System.out.println("Not Funny");
}
}
}
}