码迷,mamicode.com
首页 > 其他好文 > 详细

记票统计

时间:2016-08-20 23:27:25      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

 

import java.util.LinkedHashMap;  
import java.util.Map;  
import java.util.Scanner;  
  
  
public class MainVote1 {  
public static void main(String[] args) {  
          
        LinkedHashMap<Character,Integer> hs=new LinkedHashMap<Character,Integer>();  
          
        Scanner sca=new Scanner(System.in);  
        sca.nextLine();  
        char ch1[]=sca.nextLine().toCharArray();  
        sca.nextLine();  
        char ch2[]=sca.nextLine().toCharArray();  
          
        for(int i=0;i<ch1.length;i=i+2)  
            hs.put(ch1[i], 0);  
          
        int Invalid=0;  
        for(int i=0;i<ch2.length;i=i+2){  
            if(hs.containsKey(ch2[i])){  
                int temp=hs.get(ch2[i]);  
                hs.put(ch2[i], temp+1);  
            }  
            else Invalid++;  
        }  
        for(Map.Entry<Character, Integer> me:hs.entrySet())  
            System.out.println(me.getKey()+" : "+me.getValue());  
			System.out.print("Invalid : "+Invalid);  
    }  
}  

  技术分享

记票统计

标签:

原文地址:http://www.cnblogs.com/GumpYan/p/5791468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!