0
点赞
收藏
分享

微信扫一扫

Java乒乓球筐

谁知我新 2022-04-21 阅读 61
java哈希
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            String s = sc.nextLine();
            String[] str = s.split(" ");
            String[] A = str[0].split("");
            String[] B = str[1].split("");
            Map<String, Integer> mapA = new HashMap<>();
            Map<String, Integer> mapB = new HashMap<>();
            for(String s1 : A){
                if(mapA.containsKey(s1)){
                    mapA.put(s1, mapA.get(s1) + 1);
                }else{
                    mapA.put(s1, 1);
                }
            }
            for(String s1 : B){
                if(mapB.containsKey(s1)){
                    mapB.put(s1, mapB.get(s1) + 1);
                }else{
                    mapB.put(s1, 1);
                }
            }
            int count = 0;
            for(int i = 0; i < B.length; i++){
                if(mapA.containsKey(B[i])){
                    mapA.put(B[i], mapA.get(B[i]) - 1);
                    if(mapA.get(B[i]) < 0){
                        System.out.println("No");
                        break;
                    }
                    count++;
                }else{
                    System.out.println("No");
                    break;
                }
            }
            if(count == B.length){
                System.out.println("Yes");
            }
        }
    }
}
举报

相关推荐

0 条评论