题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int [] shuzu=new int[n];
int i=0;
while(sc.hasNextInt()){
shuzu[i++]=sc.nextInt();
}
//先排好序 1 2 3 4 5 5
i=0;
int val=500;
int count=0;
for(;i<n;i++){
for(int j=i+1;j<n;j++){
if(shuzu[j]<shuzu[i]){
int tmp=shuzu[i];
shuzu[i]=shuzu[j];
shuzu[j]=tmp;
}else if(shuzu[i]==shuzu[j]){
shuzu[j]=++val;
count++;
}
}
}
for(int k=0;k<shuzu.length-count;k++){
System.out.println(shuzu[k]);
}
}
}
查看20道真题和解析