POJ1002

 题目http://acm.pku.edu.cn/JudgeOnline/problem?id=1002

 

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Arrays;
  5. public class Main {
  6.     public static void main(String[] args) throws NumberFormatException, IOException {
  7.         BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
  8.         int times = Integer.parseInt(read.readLine());
  9.         String[] str = new String[times];
  10.         int index;
  11.         for(int i = 0 ; i < times ; i++){
  12.             str[i] = read.readLine();
  13.             char[] chars = new char[7];
  14.             index= 0;
  15.             for(int j = 0 ; j < str[i].length() ; j++){
  16.                 if(str[i].charAt(j) == '-'){
  17.                     continue;
  18.                 }else{
  19.                     char t = str[i].charAt(j);
  20.                     if(t>='0'&&t<='9'){
  21.                         chars[index++] = t;
  22.                     }else{
  23.                         chars[index++] = returnValue(t);
  24.                     }
  25.                 }
  26.             }
  27.             str[i] = String.valueOf(chars);
  28.         }
  29.         Arrays.sort(str);
  30.         int num = 1 ;
  31.         String temp = str[0];
  32.         boolean b = false;
  33.         for(int i = 1 ; i < times ; i++){
  34.             if(temp .equals(str[i])){
  35.                 num++;
  36.                 if(i == times - 1){
  37.                     if(num > 1){
  38.                         System.out.println(temp.substring(0,3) + "-" + temp.substring(3) + " " + num);
  39.                         b = true;
  40.                     }
  41.                 }
  42.             }else{
  43.                 if(num > 1){
  44.                     System.out.println(temp.substring(0,3) + "-" + temp.substring(3) + " " + num);
  45.                     b = true;
  46.                     temp = str[i];
  47.                     num = 1;
  48.                 }else{
  49.                     temp = str[i];
  50.                     num = 1;
  51.                 }
  52.             }
  53.         }
  54.         if(!b){
  55.             System.out.println("No duplicates.");
  56.         }
  57.     }
  58.     
  59.     static public char returnValue(char c){
  60.         if(c<=67&&c>=65){
  61.             return '2';
  62.         }else if(c<=70&&c>=68){
  63.             return '3';
  64.         }else if(c<=73&&c>=71){
  65.             return '4';
  66.         }else if(c<=76&&c>=74){
  67.             return '5';
  68.         }else if(c<=79&&c>=77){
  69.             return '6';
  70.         }else if(c<=83&&c>=80){
  71.             return '7';
  72.         }else if(c<=86&&c>=84){
  73.             return '8';
  74.         }else if(c<=89&&c>=87){
  75.             return '9';
  76.         }else{
  77.             return '0';
  78.         }
  79.     }
  80. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值