File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+
4
+ class Main {
5
+ public static void main (String [] args ) throws Exception {
6
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
7
+ BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
8
+ char [] a = br .readLine ().toCharArray ();
9
+ char [] b = br .readLine ().toCharArray ();
10
+
11
+ int answer = 0 ;
12
+ int bIndex = b .length - 1 ;
13
+
14
+ for (int i = a .length - 1 ; i >= 0 ; i --) {
15
+ if (a [i ] == b [bIndex ]) {
16
+ bIndex --;
17
+ } else {
18
+ answer ++;
19
+ }
20
+ }
21
+
22
+ Arrays .sort (a );
23
+ Arrays .sort (b );
24
+ if (new String (a ).equals (new String (b ))) {
25
+ bw .write (Integer .toString (answer ));
26
+ } else {
27
+ bw .write ("-1" );
28
+ }
29
+ bw .flush ();
30
+ bw .close ();
31
+ }
32
+ }
33
+
You can’t perform that action at this time.
0 commit comments