Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define NMax 100005
- #define LMax 31
- int n, m;
- typedef struct thing { // path or truck :)
- char cap[LMax];
- int idx, match;
- } thing;
- thing a[NMax], b[NMax];
- int compCap(const void *a, const void *b) {
- char *aa = ((thing *)a)->cap;
- char *bb = ((thing *)b)->cap;
- if (strlen(aa) > strlen(bb)) { return -1; }
- if (strlen(aa) < strlen(bb)) { return 1; }
- for (int i = 0; i < strlen(aa); i++) {
- if (aa[i] > bb[i]) { return -1; }
- if (aa[i] < bb[i]) { return 1; }
- }
- return 0;
- }
- int compIdx(const void *a, const void *b) {
- return ((thing *)a)->idx - ((thing *)b)->idx;
- }
- int main() {
- freopen("camioane.in", "rt", stdin);
- freopen("camioane.out", "wt", stdout);
- scanf("%d %d", &n, &m);
- for (int i = 0; i < n; i++) {
- scanf("%s", a[i].cap);
- a[i].idx = i + 1;
- }
- for (int i = 0; i < m; i++) {
- scanf("%s", b[i].cap);
- b[i].idx = i + 1;
- }
- qsort(a, n, sizeof(a[0]), compCap);
- qsort(b, m, sizeof(b[0]), compCap);
- int cnt = 0, j = 0;
- for (int i = 0; i < n; i++) {
- while (compCap(&a[i], &b[j]) == 1 && j < m) { j++; }
- if (j >= m) { break; }
- a[i].match = b[j].idx;
- j++;
- cnt++;
- }
- qsort(a, n, sizeof(a[0]), compIdx);
- printf("%d\n", cnt);
- for (int i = 0; i < n; i++) {
- printf("%d ", a[i].match);
- }
- printf("\n");
- fclose(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement