Created
March 22, 2015 10:37
-
-
Save henrybear327/7b69b8c38e6e84d85338 to your computer and use it in GitHub Desktop.
w3c(仲凱).c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
int n; | |
while (1) { | |
scanf("%d", &n); | |
if (n == 0) | |
break; | |
int a[10000] = { 0 }, b[10000] = { 0 }, i = 0; | |
for (i = 0; i < n; i++) | |
scanf("%d", &a[i]); | |
for (i = 0; i < n; i++) | |
scanf("%d", &b[i]); | |
int x[60001] = { 0 }, y[60001] = { 0 }; /*用來暫存及排序用的陣列*/ | |
for (i = 0; i < n; i++) { | |
x[a[i]]++; | |
y[b[i]]++; | |
} | |
int j = 0, sum = 0, k; | |
i = 0; | |
while (sum < n) { | |
sum += x[i]; | |
k = x[i]; | |
while (k-- > 0) { | |
a[j] = i; | |
j++; | |
} | |
i++; | |
} | |
i = 0; | |
j = 0; | |
sum = 0; | |
while (sum < n) { | |
sum += y[i]; | |
k = y[i]; | |
while (k-- > 0) { | |
b[j] = i; | |
j++; | |
} | |
i++; | |
} | |
sum = 0; | |
i = 0; | |
j = 0; | |
while (i < n && j < n) { | |
if (a[i] < b[j]) { | |
sum++; | |
j++; | |
i++; | |
} else { | |
j++; | |
} | |
} | |
printf("%d\n", sum); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment