输入包含多组数据。
每组数据第一行包含一个正整数n(1≤n≤1024)。
紧接着n行,每行包含一个电话号码,电话号码仅由连字符“-”、数字和大写字母组成。
没有连续出现的连字符,并且排除连字符后长度始终为7(美国电话号码只有7位)。
对应每一组输入,按照字典顺序输出不重复的标准数字形式电话号码,即“xxx-xxxx”形式。
每个电话号码占一行,每组数据之后输出一个空行作为间隔符。
12 4873279 ITS-EASY 888-4567 3-10-10-10 888-GLOP TUT-GLOP 967-11-11 310-GINO F101010 888-1200 -4-8-7-3-2-7-9- 487-3279 4 UTT-HELP TUT-GLOP 310-GINO 000-1213
310-1010 310-4466 487-3279 888-1200 888-4567 967-1111 000-1213 310-4466 888-4357 888-4567
import java.util.*; import java.io.*; public class Main{ //是否是数字 public static boolean isDigit(char s){ return (s >= '0' && s <= '9'); } //是否是大写 public static boolean isUpper(char s){ return (s >= 'A' && s <= 'Z'); } public static void main(String[] args) throws Exception{ Map<Character,Character> map = new HashMap<>(); String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String num = "22233344455566677778889999"; char[] alphach = alpha.toCharArray(); char[] numch = num.toCharArray(); for(int i = 0;i < alphach.length;i++){ map.put(alphach[i],numch[i]); } Set<String> set = new TreeSet<>(); String line; BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); while((line = bf.readLine()) != null){ set.clear(); int n = Integer.parseInt(line); for(int i = 0;i < n;i++){ line = bf.readLine(); char[] linech = line.toCharArray(); StringBuilder sb = new StringBuilder(); for(char ch : linech){ if(isDigit(ch)){ sb.append(ch); }else if(isUpper(ch)){ sb.append(map.get(ch)); } } line = sb.substring(0,3) + "-" + sb.substring(3); set.add(line); } for(String s : set){ System.out.println(s); } //处理下一组数据和上一组数据之间有一个空格 System.out.println(); } } }
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static char change(char c){ if (c=='A'||c=='B'||c=='C'){ return '2'; } if (c=='D'||c=='E'||c=='F'){ return '3'; } if (c=='G'||c=='H'||c=='I'){ return '4'; } if (c=='J'||c=='K'||c=='L'){ return '5'; } if (c=='M'||c=='N'||c=='O'){ return '6'; } if (c=='P'||c=='Q'||c=='R'||c=='S'){ return '7'; } if (c=='T'||c=='U'||c=='V'){ return '8'; } if (c=='W'||c=='X'||c=='Y'||c=='Z'){ return '9'; } return c; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); while (sc.hasNext()){ int n=sc.nextInt(); List<String> list=new ArrayList<>(); for (int i = 0; i < n; i++) { String str=sc.next(); String s=""; str=str.replace("-",""); int count=0; for (int j = 0; j < 7; j++) { count++; s += change(str.charAt(j)); if (count == 3){ s += "-"; } } if (!list.contains(s)) { list.add(s); } } Collections.sort(list); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } System.out.println(); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); while(scanner.hasNext()){ ArrayList<String> arrayList=new ArrayList<>(); int n=scanner.nextInt(); String [] str=new String[n]; for (int i = 0; i <str.length ; i++) { str[i]=scanner.next(); String ret=toCoverse(str[i]).toString(); ret=ret.substring(0,3) +"-"+ret.substring(3,7); if(!arrayList.contains(ret)){ arrayList.add(ret); } } Collections.sort(arrayList); for (int i = 0; i <arrayList.size() ; i++) { System.out.println(arrayList.get(i)); } scanner.nextLine(); } } public static StringBuilder toCoverse(String s) { StringBuilder list=new StringBuilder(); char []ch=s.toCharArray(); for (int i = 0; i <ch.length ; i++) { if(ch[i]>='0'&&ch[i]<='9'){ list.append(ch[i]); } if(ch[i]>='A'&&ch[i]<='B'){ list.append('2'); } if(ch[i]>='D'&&ch[i]<='F'){ list.append('3'); } if(ch[i]>='G'&&ch[i]<='I'){ list.append('4'); } if(ch[i]>='J'&&ch[i]<='L'){ list.append('5'); } if(ch[i]>='M'&&ch[i]<='O'){ list.append('6'); } if(ch[i]>='P'&&ch[i]<='S'){ list.append('7'); } if(ch[i]>='T'&&ch[i]<='V'){ list.append('8'); } if(ch[i]>='W'&&ch[i]<='Z'){ list.append('9'); } } return list; } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] map = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", "22233344455566677778889999"}; while (sc.hasNext()) { int n = sc.nextInt(); Set<String> set = new TreeSet<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i ++ ) { char[] ch = sc.next().replace("-", "").toCharArray(); for (int j = 0; j < ch.length; j ++ ) { if(j == 3) sb.append("-"); if(Character.isLetter(ch[j])) sb.append(map[1].charAt(map[0].indexOf(ch[j]))); else sb.append(ch[j]); } set.add(sb.toString()); sb.delete(0, sb.length()); } for (String s:set) System.out.println(s); System.out.println(); } } }