---
# System prepended metadata

title: Lab4 參考解答

---

# Lab4 參考解答

# Box, Box, Give Me More Box
> Author: 110263029
```c=
#include <stdio.h>

void swap(int *xp, int *yp){
    int tmp = *xp;
    *xp = *yp;
    *yp = tmp;
    return;
}

int main(){
    int n, l, arr[55] = {0};
    scanf("%d", &n);
    while(n--){
        int cnt = 0;
        scanf("%d", &l);
        for(int i = 0; i < l; i++){
            scanf("%d", &arr[i]);
        }
        for(int i = 0; i < l-1; i++){
            for(int j = l-1; j > i; j--){
                if(arr[j-1] > arr[j]){
                    swap(&arr[j], &arr[j-1]);
                    cnt++;
                }
            }
        }
        printf("%d\n", cnt);
    }
}
```

# Machine Maintenance
> Author: 111550162

```c=
#include <stdio.h>

int main()
{
    int testcase;
    scanf("%d", &testcase);
    while(testcase--)
    {
        int n;
        int d;
        scanf("%d", &d);
        scanf("%d", &n);
        int daycount=0;
        int cal[4000]={};
        for(int i=0;i<n;i++)
        {
            int a;
            scanf("%d", &a);
            for(int j=1;j<=d;j++)
            {
                if(j%7!=0&&j%7!=6&&j%a==0)
                    cal[j]=1;
            }
        }
        for(int i=1;i<=d;i++)
            daycount+=cal[i];
        printf("%d\n", daycount);


    }

    return 0;
}
```