File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .*;
2+
3+ public class Main
4+ {
5+ static boolean check_fibo (ArrayList <Integer > n )
6+ {
7+ for (int i = 2 ; i < n .size (); i ++)
8+ {
9+ if (n .get (i ) != n .get (i - 1 ) + n .get (i - 2 ))
10+ {
11+ return false ;
12+ }
13+ }
14+ return true ;
15+ }
16+
17+ static String solve (String str )
18+ {
19+ HashMap <Character , Integer > a = new HashMap <>();
20+ for (int i = 0 ; i < str .length (); i ++)
21+ {
22+ a .put (str .charAt (i ), a .getOrDefault (str .charAt (i ), 0 ) + 1 );
23+ }
24+ if (a .size () < 3 )
25+ {
26+ return "Dynamic" ;
27+ }
28+ ArrayList <Integer > n1 = new ArrayList <>(a .values ());
29+ Collections .sort (n1 );
30+ ArrayList <Integer > n2 = new ArrayList <>(n1 );
31+ n2 .set (0 , n1 .get (1 ));
32+ n2 .set (1 , n1 .get (0 ));
33+ return check_fibo (n1 ) || check_fibo (n2 ) ? "Dynamic" : "Not" ;
34+ }
35+
36+ public static void main (String args [])
37+ {
38+ Scanner s = new Scanner (System .in );
39+ int x = s .nextInt ();
40+ while (x -- > 0 )
41+ {
42+ String str = s .next ();
43+ System .out .println (solve (str ));
44+ }
45+ s .close ();
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments