-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMain.java
46 lines (39 loc) · 871 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package basicLevel1039;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char[] sales = in.nextLine().toCharArray();
char[] bought = in.nextLine().toCharArray();
in.close();
Arrays.sort(sales);
Arrays.sort(bought);
int debt = 0;
for (int i = 0, j = 0; j < bought.length;) {
if (i != sales.length) {
if (sales[i] == bought[j]) {
i++;
j++;
} else if (sales[i] > bought[j]) {
j++;
debt++;
} else {
// sales[i] < bought[j];
i++;
if (i == sales.length) {
debt += sales.length - i;
}
}
} else {
debt += bought.length - j;
break;
}
}
if (debt == 0) {
System.out.println("Yes " + (sales.length - bought.length));
} else {
System.out.println("No " + debt);
}
}
}