- 论坛徽章:
- 2
|
- #include <stdlib.h>
- void skip_list(const int **a, int *alen, const int num)
- {
- const int *pa;
- int i;
- pa = *a;
- for (i = 0; i < *alen; i++) {
- if (pa[i] + 1 >= num) {
- break;
- }
- }
- *a = pa + i;
- *alen -= i;
- }
- int compare_list(const int *a, int alen, const int *b, int blen)
- {
- int count;
- count = 0;
- while (alen > 0 && blen > 0) {
- skip_list(&a, &alen, *b);
- if (abs(*a - *b) <= 1) {
- a++;
- alen--;
- b++;
- blen--;
- count += 2;
- }
- skip_list(&b, &blen, *a);
- if (abs(*a - *b) <= 1) {
- a++;
- alen--;
- b++;
- blen--;
- count += 2;
- }
- }
- return count;
- }
- /* TEST */
- #include <stdio.h>
- #define LEN(a) (sizeof(a)/sizeof((a)[0]))
- int main(void)
- {
- static int a[] = {26,35,1105,1203,5490,12322};
- static int b[] = {25,34,1202,3442,5489,12324};
- int retval;
- retval = compare_list(a, LEN(a), b, LEN(b));
- if (retval * 100 / (LEN(a) + LEN(b)) >= 80) {
- printf("same: %d/%d\n", retval, LEN(a)+LEN(b));
- }else {
- printf("not same: %d/%d\n", retval, LEN(a)+LEN(b));
- }
- return 0;
- }
复制代码 |
|