File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+
3+ public class Main {
4+
5+ private static int N ;
6+
7+ public static void main (String [] args ) throws IOException {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
9+ N = Integer .parseInt (br .readLine ());
10+ dfs ("1" );
11+ }
12+
13+ public static void dfs (String strNum ) {
14+ if (strNum .length () == N ) {
15+ System .out .println (strNum );
16+ System .exit (0 );
17+ return ;
18+ }
19+
20+ for (int j =1 ; j <=3 ; j ++) {
21+ String str = strNum + j ;
22+ if (check (str )) {
23+ dfs (str );
24+ }
25+ }
26+ }
27+
28+ public static boolean check (String strNum ) {
29+ int len = strNum .length ();
30+ for (int i =1 ; i <=len /2 ; i ++) {
31+ String str1 = strNum .substring (len -i , len );
32+ String str2 = strNum .substring (len -i *2 , len -i );
33+ if (str1 .equals (str2 )) {
34+ return false ;
35+ }
36+ }
37+ return true ;
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments