import sys n = int(input()) # 读取序列长度 a = list(map(int, input().split())) # 读取序列 b = [] # 初始化结果序列 for i in range(n): count = 0 # 初始化计数器 for j in range(i): if a[j] < a[i]: count += 1 # 如果前面的元素小于当前元素,计数器加1 b.append(count) # 将当前元素的计数结果追加到结果序列中 print(' '.join(map(str, b))) # 输出结果序列
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); List<Integer> list = new ArrayList(); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int a = in.nextInt(); list.add(a); int q = 0; for(int i:list){ if(a>i) q++; } System.out.print(q+" "); } } }