| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Java解答import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
HashMap<String,String> hm = new HashMap<String,String>(35);
for(int i = 0; i < 10; i ++)
hm.put(Integer.toString(i), Integer.toString(i));
String abc = "ABCDEFGHIJKLMNOPRSTUVWXY";
int value = 1;
for(int i = 0; i < abc.length(); i ++)
{
if(i%3 == 0)
value += 1;
hm.put(Character.toString(abc.charAt(i)), Integer.toString(value));
}
hm.put("-", "");
Scanner in = new Scanner(System.in);
int numOfLines = in.nextInt();
ArrayList<String> arr = new ArrayList<String>();
String doneLine,line;
for(int i =0; i < numOfLines; i ++)
{
doneLine = "";
line = in.next();
for(int j = 0; j < line.length(); j ++)
doneLine += hm.get(Character.toString(line.charAt(j)));
arr.add(doneLine);
}
Collections.sort(arr);
boolean dup = false;
int num = 1;
String first = arr.get(0);
int pointer = 1;
int arrSize = arr.size();
while(pointer < arrSize)
{
if(first.equals(arr.get(pointer)))
{
num += 1;
pointer += 1;
if(pointer == arr.size())
{
dup = true;
System.out.println(first.substring(0,3)+"-"+first.substring(3,7)+" "+num);
}
}
else
{
if(num > 1)
{
dup = true;
System.out.println(first.substring(0,3)+"-"+first.substring(3,7)+" "+num);
}
num = 1;
first = arr.get(pointer);
pointer += 1;
}
}
if(!dup)
System.out.println("No duplicates.");
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator