解题思路:
import java.util.Arrays; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class C1190 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); if(n == 0) break; int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = sc.nextInt(); } Set<Integer> set = new TreeSet<Integer>(); for(int i = 0; i < n-1; i++){ for(int j = i+1; j < n; j++){ if(isRelate(a[i], a[j])){ set.add(i); set.add(j); } } } if(set.size() == n){ System.out.println("None"); }else{ for(Integer index : set){ a[index] = Integer.MAX_VALUE; } Arrays.sort(a); for(int i = 0; i < n && a[i] != Integer.MAX_VALUE; i++){ if(i == 0) System.out.printf("%d", a[i]); else System.out.printf(" %d", a[i]); } System.out.println(); } } sc.close(); } //判断是否为相关数 private static boolean isRelate(int a, int b){ char[] chsA = String.valueOf(a).toCharArray(); char[] chsB = String.valueOf(b).toCharArray(); //1. 长度不一致返回false if(chsA.length != chsB.length) return false; //2. 判断是否含有相同数字 for(int i = 0; i < chsA.length; i++){ boolean flag = false; for(int j = 0; j < chsB.length; j++){ if(chsA[i] == chsB[j]){ flag = true; chsA[i] = 'a'; chsB[j] = 'a'; } } if(!flag) return false; } return true; } }
注意事项:
参考代码:
0.0分
0 人评分
C语言训练-计算1977!* (C++代码)浏览:848 |
A+B for Input-Output Practice (V) (C语言代码)浏览:617 |
【金明的预算方案】 (C++代码)浏览:838 |
printf基础练习2 (C语言代码)浏览:746 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:681 |
震宇大神的杀毒软件 (C语言代码)浏览:1079 |
图形输出 (C语言代码)浏览:937 |
输入输出格式练习 (C语言代码)浏览:842 |
输入输出格式练习 (C语言代码)浏览:743 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:713 |