//小红想买珠子做自己喜欢的珠串摊主不拆开卖,
//判断某串珠子是否包含了全部自己想要的珠子,
//如果是,则有多少多余的珠子,如果不是,还缺多少
public class BuyBead {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
String s= sc.nextLine();
String res = sc.nextLine();
//Ctrl+P:查看方法参数
//Ctrl+Q:查看类、方法、属性注释
Map<Character,Integer> map = new HashMap<>();
for (int i = 0; i < s.length();i++) {
int length = map.getOrDefault(s.charAt(i),0);
map.put(s.charAt(i),length+1);
}
int count = 0;
for (int j = 0; j < res.length();j++) {
int len = map.getOrDefault(res.charAt(j),0);
if (len <= 0) {
count ++;
}
map.put(res.charAt(j),len-1);
}
if (count == 0) {
System.out.println("yes" + " " + (s.length()-res.length()));
} else {
System.out.println("no" + " " + count);
}
}
sc.close();
}
}
小红买珠子
最新推荐文章于 2020-09-26 20:30:16 发布