File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ There are two strings: A and B. Print 1 if string B occurs at the end of string A. Otherwise, print 0.
3
+ */
4
+
5
+ import java .io .*;
6
+ public class Main {
7
+ public static void main (String [] args ) throws IOException {
8
+ File file = new File (args [0 ]);
9
+ BufferedReader br = new BufferedReader (new FileReader (file ));
10
+ String line ;
11
+ while ((line = br .readLine ()) != null ) {
12
+ String [] s = line .split ("," );
13
+ int length2 = s [1 ].length ();
14
+ int length1 = s [0 ].length ();
15
+ String s1 = "" ;
16
+ if (s [0 ].length ()>=s [1 ].length ()) {
17
+ s1 = s [0 ].substring (length1 -length2 , length1 );
18
+ }
19
+ if (s1 .equalsIgnoreCase (s [1 ])) {
20
+ System .out .println ("1" );
21
+ }
22
+ else {
23
+ System .out .println ("0" );
24
+ }
25
+ }
26
+ br .close ();
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments