Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Java code

Posted by ayxg at 2011-12-07 14:21:31 on Problem 1002
import java.util.*;
public class Mainm {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		Map<String, String> keymap = new HashMap<String, String>();
		keymap.put("A", "2");keymap.put("B", "2");keymap.put("C", "2");
		keymap.put("D", "3");keymap.put("E", "3");keymap.put("F", "3");
		keymap.put("G", "4");keymap.put("H", "4");keymap.put("I", "4");
		keymap.put("J", "5");keymap.put("K", "5");keymap.put("L", "5");
		keymap.put("M", "6");keymap.put("N", "6");keymap.put("O", "6");
		keymap.put("P", "7");keymap.put("R", "7");keymap.put("S", "7");
		keymap.put("T", "8");keymap.put("U", "8");keymap.put("V", "8");
		keymap.put("W", "9");keymap.put("X", "9");keymap.put("Y", "9");
		Map<String, Integer> map = new HashMap<String, Integer>();
		while (n > 0) {
			String line = sc.nextLine();
			String std = "";
			for (int i = 0; i < line.length(); ++i) {
				if (std.length() == 3) std += "-";
				Character c = line.charAt(i);
				if (c == '-' || c == 'Q' || c == 'Z') continue;
				if (Character.isDigit(c) || Character.isUpperCase(c)) {
					if(keymap.containsKey(c.toString())){
						std=std+keymap.get(c.toString());
					}
					else{
						std=std+c;
					}
					
				}
			}
			if(map.containsKey(std)){
				map.put(std, map.get(std)+1);
			}else{	
				map.put(std,1);
			}
			--n;
		}
	    Set<String> tkey = map.keySet();
	    TreeSet key = new TreeSet(tkey);
	    boolean flag = true;
        for (Iterator it = key.iterator(); it.hasNext();) {
            String s = (String) it.next();
            if(map.get(s)>1) {
            	System.out.println(s+" "+map.get(s)); flag = false;
            }

        }
        if (flag) System.out.println("No duplicates. ");
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator