#42818:


suyueh (suyueh)

學校 : 不指定學校
編號 : 272111
來源 : [101.12.162.212]
最後登入時間 :
2024-11-10 22:20:41
b373. [福州19中]车厢重组 | From: [125.229.229.84] | 發表日期 : 2024-10-05 14:14

#include <stdio.h>
#define SWAP(x, y) x^=(y^=(x^=y))

int index[10000];

int main()
{
int n, max, count;
while (scanf(" %d", &n) == 1)
{
max = n - 1, count = 0;
for (int i = 0; i < n; i++)
scanf(" %d", &index[i]);
for (int i = 0; i < max; i++)
{
for (int j = 0; j < max - i; j++)
{
if (index[j] > index[j + 1])
SWAP(index[j], index[j + 1]), count++;
}
}
printf("%d\n", count);
}
return 0;
}
 
ZeroJudge Forum