ACM 题目1167:数组排序

 
  
题目描述:

输入一个数组的值,求出各个值从小到大排序后的次序。

 
  
输入:

输入有多组数据。
每组输入的第一个数为数组的长度n(1<=n<=10000),后面的数为数组中的值,以空格分割。

 
  
输出:

各输入的值按从小到大排列的次序(最后一个数字后面没有空格)。

 
  
样例输入:
4
-3 75 12 -3
 
  
样例输出:
1 3 2 1


import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;


public class Main {
static int[] arr, arr2;
static int n;

public static void main(String[] args) {
Scanner s = new Scanner(new BufferedInputStream(System.in));
while (s.hasNextInt()) {
n = s.nextInt();
arr = new int[n];
arr2 = new int[n];
for (int i = 0; i < n; i++) {
int temp = s.nextInt();
arr[i] = temp;
arr2[i] = temp;
}
Arrays.sort(arr2);
for (int i = 0; i < n; i++) {
int index = 0;
for (int j = 0; j < n; j++) {
if (j != 0 && arr2[j] == arr2[j - 1])
index--;
index++;
if (arr[i] == arr2[j]) {
if (i == 0)
System.out.print(index);
else
System.out.print(" " + index);
break;
}
}
}
System.out.println();
}
}
}

转载于:https://www.cnblogs.com/love533/archive/2012/03/16/2400832.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值