File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
CodeTree/ํ๋ก๊ทธ๋๋ฐ๊ธฐ์ด/09_๋ฌธ์์ด Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+ /**
4+ * 1. ๋ฌธ์ ์ ๋ณด
5+ * - ์ ๋ชฉ : ๋ฏธ๋ ํ์
6+ * - ๋งํฌ : https://www.codetree.ai/missions/4/problems/number-of-pushes/description
7+ * 2. ํ์ดํต์ฌ
8+ * - ๋ฌธ์์ด ๋น๊ต
9+ * 3. ํ์ดํ๊ธฐ
10+ * - ๊ฐ๋จํ ๋ฌธ์ ํ์ด
11+ */
12+ public class Main {
13+ public static void main (String [] args ) throws Exception {
14+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
15+ String A = br .readLine (), B = br .readLine ();
16+ int count = A .equals (B ) ? 0 : countShift (A , B );
17+ System .out .println (count > A .length () ? -1 : count );
18+ }
19+
20+ private static String rightShift (String str ) {
21+ int lastIdx = str .length () - 1 ;
22+ return str .substring (1 ) + str .charAt (0 );
23+ }
24+
25+ private static int countShift (String A , String B ) {
26+ int count = 1 ;
27+ for (count = 1 ;count <= A .length ();count ++) {
28+ String newB = rightShift (B );
29+ if (A .equals (newB )) break ;
30+ B = newB ;
31+ }
32+ return count ;
33+ }
34+ }
You canโt perform that action at this time.
0 commit comments