PAT L1-027 之我写的狗屎代码

import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(System.in);
HashSet<Integer> hashSet=new HashSet<>();
String c=sc.nextLine();
char x[]=c.toCharArray();
int x1[]=new int[x.length];
for (int i = 0; i < x1.length; i++) {
x1[i]=x[i]-'0';
hashSet.add(x1[i]);
}
Object[] x2 =hashSet.toArray();
int x3[]=new int [x2.length];
for (int i = 0; i < x2.length; i++) {
x3[i]=(int) x2[i];
}
Arrays.sort(x3);
System.out.print("int[] arr = new int[]{");
for (int i=x3.length-1;i>=0;i--){
System.out.print(x3[i]);
if(i!=0){
System.out.print(",");
}
}
System.out.println("};");
int x4[]=new int[11];

for (int i = 0; i < x1.length; i++) {
for (int j = 0; j < x3.length; j++) {
if(x1[i]==x3[j]){
x4[i]=x3.length-j-1;
}
}
}
System.out.print("int[] index = new int[]{");
for (int i = 0; i < x4.length; i++) {
System.out.print(x4[i]);
if(i!=x4.length-1){
System.out.print(",");
}
}
System.out.print("};");

}
}


posted @ 2022-04-18 23:27  森屿微央  阅读(85)  评论(0)    收藏  举报