---
# System prepended metadata

title: Lab2 參考解答

---

# Lab2 參考解答

# All you need is permutation
> Author: TA
```c=
#include <stdio.h>
#define MAXLEN 1000
#define STRLEN 100

int main(){
    int testCase, length;
    int order[MAXLEN];
    char array[MAXLEN][STRLEN];
    scanf("%d", &testCase);
    while(testCase--){
        for(length=0; scanf("%d", &order[length++]), getchar() != '\n';);
        for(int i=0; i<length; i++){
            scanf("%s", &array[order[i]-1]);
        }
        for(int i=0; i<length; i++){
            puts(array[i]);
        }
        printf("\n");
    }
    return 0;
}
```

# Blockchain is watching you
> Author: 111550083
```c=
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int n;
    char text[] = "the quick brown fox jumps over the lazy dog";
    scanf("%d\n",&n);
    for(int i=0;i<n;i++)
    {
        char str[100][90];
        char ch[26];
        int num = 0;
        int same = 0;
        while(gets(str[num])!=NULL &&str[num][0] != '\0')
        {
            if(strlen(str[num])==strlen(text) && same != 2)
            {
                for(int j = 0;j<26;j++) ch[j] = '\0';
                same = 1;
                for(int j = 0;j<strlen(text);j++)
                {
                    if(str[num][j]!=' ')
                    {
                        if(ch[str[num][j]-'a'] != text[j] && ch[str[num][j]-'a'] !='\0')
                        {
                            same = 0;
                            break;
                        }
                        else ch[str[num][j]-'a'] = text[j];
                    }
                    if(str[num][j]==' ' && text[j]!=' ')
                    {
                        same = 0;
                        break;
                    }
                    if(str[num][j]!=' ' && text[j]==' ')
                    {
                        same = 0;
                        break;
                    }
                }
                if(same == 1)  same = 2;
            }
            num++;
        }
        if(same == 0)
        {
            printf("No solution.");
            if(i<n-1) printf("\n\n");
        }
        else
        {
            for(int j = 0;j<num;j++)
            {
                for(int k = 0;k<strlen(str[j]);k++)
                {
                    if(str[j][k] == ' ')
                    {
                        printf(" ");
                        continue;
                    }
                    printf("%c",ch[str[j][k]-'a']);
                }
                if(i== n-1&&j==num-1) ;
                else printf("\n");
            }
            if(i<n-1) printf("\n");
        }
    }
}
```