File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ //You are given a list of numbers which is supplemented with positions that have to be swapped.
2
+
3
+ import java .io .*;
4
+ import java .util .*;
5
+ public class Main {
6
+ public static void main (String [] args ) throws IOException {
7
+ File file = new File (args [0 ]);
8
+ BufferedReader br = new BufferedReader (new FileReader (file ));
9
+ String line ;
10
+ while ((line = br .readLine ()) != null ) {
11
+ String [] a = line .split (":" );
12
+ String [] b = a [0 ].split (" " );
13
+ String [] c = a [1 ].replace (" " , "" ).split ("," );
14
+ for (String s : new Main ().swap (b , c )) {
15
+ System .out .print (s + " " );
16
+ }
17
+ System .out .println ();
18
+ }
19
+ br .close ();
20
+ }
21
+
22
+ String [] swap (String [] s , String [] h ) {
23
+ String g ;
24
+ for (int i = 0 ; i < h .length ; i ++) {
25
+ g = h [i ];
26
+ String [] d = g .split ("-" );
27
+ int a = Integer .parseInt (d [0 ]);
28
+ int b = Integer .parseInt (d [1 ]);
29
+ String c = s [a ];
30
+ String e = s [b ];
31
+ s [a ] = e ;
32
+ s [b ] = c ;
33
+ }
34
+ return s ;
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments