题解 | #记票统计#

记票统计

https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            //候选人数
            int n = sc.nextInt();
            //候选人
            String[] man = new String[n];
            for (int i = 0; i < n; i++) {
                man[i] = sc.next();
            }
            //投票人数
            int m = sc.nextInt();
            //投的票
            String[] votes = new String[m];
            for (int i = 0; i < m; i++) {
                votes[i] = sc.next();
            }
            int invalid = m;
            for (String s : man) {
                int count = 0;
                for (String vote : votes) {
                    if (s.equals(vote)) {
                        count++;
                    }
                }
                System.out.println(s + " : " + count);
                invalid -= count;
            }
            System.out.println("Invalid : " + invalid);
        }
    }

}

全部评论

相关推荐

11-10 21:00
门头沟学院 Java
程序员牛肉:没啥必要了,3月末就开暑期实习了,你现在找还不一定能找到。看你啥学历了。 双非基本代表想进好公司无望了。211的话,现在继续沉淀,零日常实习参加暑期其实也压力不太大
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务