File tree Expand file tree Collapse file tree 3 files changed +102
-0
lines changed Expand file tree Collapse file tree 3 files changed +102
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ public static boolean check (String a , String b ) {
7+ if (a .length () != b .length ())
8+ return false ;
9+
10+ int [] count = new int [26 ];
11+
12+ for (int i = 0 ; i < a .length (); ++i ) {
13+ count [a .charAt (i ) - 'a' ]++;
14+ count [b .charAt (i ) - 'a' ]--;
15+ }
16+
17+ for (int c : count ) {
18+ if (c != 0 ) {
19+ return false ;
20+ }
21+ }
22+ return true ;
23+ }
24+
25+
26+ public static void main (String [] args ) throws Exception {
27+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
28+
29+ int n = Integer .parseInt (br .readLine ());
30+
31+ for (int i = 0 ; i < n ; ++i ) {
32+ String [] str = br .readLine ().split (" " );
33+ String a = str [0 ];
34+ String b = str [1 ];
35+ if (check (a ,b )) {
36+ System .out .println ("Possible" );
37+ } else {
38+ System .out .println ("Impossible" );
39+ }
40+ }
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ public static void main (String [] args ) throws Exception {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8+
9+ String [] input = br .readLine ().split (" " );
10+ int n = Integer .parseInt (input [0 ]);
11+ int k = Integer .parseInt (input [1 ]);
12+
13+ Map <Integer , Integer > s = new HashMap <>();
14+ Map <Integer , Integer > f = new HashMap <>();
15+
16+ for (int i = 0 ; i < n ; ++i ) {
17+ input = br .readLine ().split (" " );
18+ int b = Integer .parseInt (input [0 ]);
19+ int a = Integer .parseInt (input [1 ]);
20+ if (b == 0 ) {
21+ s .put (a , s .getOrDefault (a , 0 ) + 1 );
22+ } else {
23+ f .put (a , f .getOrDefault (a , 0 ) + 1 );
24+ }
25+ }
26+ int ans = 0 ;
27+ for (Map <Integer , Integer > map : List .of (s , f )) {
28+ for (int count : map .values ()) {
29+ ans += (count + k - 1 ) / k ;
30+ }
31+ }
32+ System .out .println (ans );
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ public static void main (String [] args ) throws Exception {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8+
9+ String input1 = br .readLine ();
10+ String input2 = br .readLine ();
11+
12+ int [] arr = new int [26 ];
13+ for (int i = 0 ; i < input1 .length (); ++i ) {
14+ arr [input1 .charAt (i ) - 'a' ]++;
15+ }
16+ for (int i = 0 ; i < input2 .length (); ++i ) {
17+ arr [input2 .charAt (i ) - 'a' ]--;
18+ }
19+
20+ int ans = 0 ;
21+ for (int i = 0 ; i < 26 ; ++i ) {
22+ ans += Math .abs (arr [i ]);
23+ }
24+ System .out .println (ans );
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments