#42818: ____


suyueh (suyueh)

學校 : 不指定學校
編號 : 272111
來源 : [125.228.45.241]
最後登入時間 :
2025-06-02 18:21:06

#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;
}