题目http://acm.pku.edu.cn/JudgeOnline/problem?id=1002
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) throws NumberFormatException, IOException {
- BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
- int times = Integer.parseInt(read.readLine());
- String[] str = new String[times];
- int index;
- for(int i = 0 ; i < times ; i++){
- str[i] = read.readLine();
- char[] chars = new char[7];
- index= 0;
- for(int j = 0 ; j < str[i].length() ; j++){
- if(str[i].charAt(j) == '-'){
- continue;
- }else{
- char t = str[i].charAt(j);
- if(t>='0'&&t<='9'){
- chars[index++] = t;
- }else{
- chars[index++] = returnValue(t);
- }
- }
- }
- str[i] = String.valueOf(chars);
- }
- Arrays.sort(str);
- int num = 1 ;
- String temp = str[0];
- boolean b = false;
- for(int i = 1 ; i < times ; i++){
- if(temp .equals(str[i])){
- num++;
- if(i == times - 1){
- if(num > 1){
- System.out.println(temp.substring(0,3) + "-" + temp.substring(3) + " " + num);
- b = true;
- }
- }
- }else{
- if(num > 1){
- System.out.println(temp.substring(0,3) + "-" + temp.substring(3) + " " + num);
- b = true;
- temp = str[i];
- num = 1;
- }else{
- temp = str[i];
- num = 1;
- }
- }
- }
- if(!b){
- System.out.println("No duplicates.");
- }
- }
- static public char returnValue(char c){
- if(c<=67&&c>=65){
- return '2';
- }else if(c<=70&&c>=68){
- return '3';
- }else if(c<=73&&c>=71){
- return '4';
- }else if(c<=76&&c>=74){
- return '5';
- }else if(c<=79&&c>=77){
- return '6';
- }else if(c<=83&&c>=80){
- return '7';
- }else if(c<=86&&c>=84){
- return '8';
- }else if(c<=89&&c>=87){
- return '9';
- }else{
- return '0';
- }
- }
- }