#include <stdio.h>
#include <stdlib.h>
#define MAX_N 100
int n;
int tian[MAX_N], qi[MAX_N];
int compare(const void *x, const void *y) {
return *(int *)y - *(int *)x;
}
int main() {
while (scanf("%d", &n) && n) {
for (int i = 0; i < n; ++i) {
scanf("%d", &tian[i]);
}
for (int i = 0; i < n; ++i) {
scanf("%d", &qi[i]);
}
qsort(tian, n, sizeof(int), compare);
qsort(qi, n, sizeof(int), compare);
int tian_head = 0, qi_head = 0, tian_tail = n - 1, qi_tail = n - 1;
int ans = 0;
while (tian_head <= tian_tail) {
if (tian[tian_tail] > qi[qi_tail]) {
--tian_tail;
--qi_tail;
ans -= 200;
} else if (tian[tian_tail] < qi[qi_tail]) {
++tian_head;
--qi_tail;
ans += 200;
} else {
if (tian[tian_head] > qi[qi_head]) {
++tian_head;
++qi_head;
ans += 200;
} else {
if (tian[tian_head] < qi[qi_tail]) {
++tian_head;
--qi_tail;
ans -= 200;
}
}
}
}
printf("%d\n", ans);
}
return 0;
}
田忌赛马 C++题目(一维数组)
最新推荐文章于 2024-09-08 13:46:12 发布