62,614
社区成员
发帖
与我相关
我的任务
分享
import java.math.*;
import java.util.*;
public class Main
{
static int[] ten = {1, 10, 100, 1000, 10000, 100000, 1000000};
static char check(char c)
{
if(c <= '9' && c >= '0')
{
return c;
}
if(c < 'Q')
{
return (char)('2' + (c - 'A') / 3);
}
else
{
return (char)('7' + (c - 'Q') / 3);
}
}
static class Counter
{
public int value = 1;
}
public static void main(String[] args)
{
try
{
Scanner scan = new Scanner(System.in);
int total = scan.nextInt();
Map<String, Counter> map = new TreeMap<String, Counter>();
scan.nextLine();
char c;
for(int i = 0; i < total; i++)
{
String temp = scan.nextLine();
StringBuilder builder = new StringBuilder();
for(int j = 0, k = 0; j < temp.length(); j++)
{
if(temp.charAt(j) == '-')
{
continue;
}
c = check(temp.charAt(j));
builder.append(c);
}
String str = builder.toString();
Counter counter = (Counter)map.get(str);
if(counter == null)
{
counter = new Counter();
map.put(str, counter);
}
else
{
counter.value++;
}
}
boolean hasResult = false;
/* 去掉注释测试通过
for (Map.Entry entry : map.entrySet())
{
String str = entry.getKey().toString();
Counter counter = map.get(str);//(Counter)entry.getValue();结果均正确
if (counter.value > 1)
{
System.out.println(str.substring(0, 3) + "-" + str.substring(3) + " " + counter.value);
hasResult = true;
}
}*/
/* 去掉注释测试不通过 Runtime Error
for(String str : map.keySet())
{
Counter counter = map.get(str);
if(counter.value > 1)
{
System.out.println(str.substring(0, 3) + "-" + str.substring(3) + " " + counter.value);
hasResult = true;
}
}*/
if(!hasResult)
{
System.out.print("No duplicates.");
return;
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}