| ||||||||||
| 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 | |||||||||
Re:原题16组数据全都在自己的机器上过了,但在poj上。。。。郁闷了In Reply To:Re:原题16组数据全都在自己的机器上过了,但在poj上。。。。郁闷了 Posted by:aslanwu at 2010-06-02 20:45:57 为什么有时候AC有时候RTE??
这是咋回事?
import java.util.*;
public class Main {
/**
* @param args
*/
public static String convert(String s)
{
String out = "";
char bit;
for(int i = 0; i < s.length(); i++)
{
bit = s.charAt(i);
if(bit >= '0' && bit <= '9')
out += bit;
else if(bit == 'A' || bit == 'B' || bit == 'C')
out += '2';
else if(bit == 'D' || bit == 'E' || bit == 'F')
out += '3';
else if ( bit == 'G' || bit == 'H' || bit == 'I')
out += "4";
else if (bit == 'J' || bit == 'K' || bit == 'L')
out += "5";
else if (bit == 'M' || bit == 'N' || bit == 'O')
out += "6";
else if (bit == 'P' || bit == 'R' || bit == 'S')
out += "7";
else if (bit == 'T' || bit == 'U' || bit == 'V')
out += "8";
else if (bit == 'W' || bit == 'Y' || bit == 'X')
out += "9";
}
return out.substring(0, 3) + "-" + out.substring(3);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int n;
String inString;
Scanner input = new Scanner(System.in);
n = input.nextInt();
HashMap<String, Integer> hashTable = new HashMap<String, Integer>();
for(int i = 0; i < n; i++)
{
inString = input.next();
inString = convert(inString);
if(hashTable.get(inString) == null)
hashTable.put(inString, 1);
else
{
int newVal = hashTable.get(inString) + 1;
hashTable.put(inString, newVal);
}
}
if(hashTable.keySet().size() == n)
System.out.println("No duplicates.");
else
{
ArrayList<num> list = new ArrayList<num>();
for(Map.Entry<String, Integer> entry : hashTable.entrySet())
{
if(entry.getValue() > 1)
list.add(new num(entry.getKey(), entry.getValue()));
}
Collections.sort(list, new Comparator()
{
public int compare(Object arg0, Object arg1)
{
num c1 = (num) arg0;
num c2 = (num) arg1;
return c1.phoneNum.compareTo(c2.phoneNum);
}
});
for(num a : list)
{
System.out.println(a.phoneNum + " " + a.appTimes);
}
}
}
}
class num
{
String phoneNum;
int appTimes;
public num(String aNum, int aTimes)
{
phoneNum = aNum;
appTimes = aTimes;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator