题解 | #记票统计#

记票统计

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);
        }
    }

}

全部评论

相关推荐

求个付费实习岗位:这种就是吃满时代红利又没啥技术水平,只能靠压力学生彰显优越感的老登,别太在意了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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