MCPcopy Create free account
hub / github.com/MohamedMetwalli5/HackerRank-Solutions / FunnyString

Class FunnyString

ProblemSolving (General)/FunnyString.java:9–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import java.util.regex.*;
8
9public class FunnyString {
10
11 // Complete the funnyString function below.
12 static String funnyString(String s) {
13 StringBuilder str = new StringBuilder(s);
14 String reverse = str.reverse().toString();
15 for(int i=0;i<s.length()-1;i++){
16 if(Math.abs((int)s.charAt(i) - (int)s.charAt(i+1)) != Math.abs((int)reverse.charAt(i) - (int)reverse.charAt(i+1))){
17 return "Not Funny";
18 }
19 }
20 return "Funny";
21
22 }
23
24 private static final Scanner scanner = new Scanner(System.in);
25
26 public static void main(String[] args) throws IOException {
27 BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
28
29 int q = scanner.nextInt();
30 scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
31
32 for (int qItr = 0; qItr < q; qItr++) {
33 String s = scanner.nextLine();
34
35 String result = funnyString(s);
36
37 bufferedWriter.write(result);
38 bufferedWriter.newLine();
39 }
40
41 bufferedWriter.close();
42
43 scanner.close();
44 }
45}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected