Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.8 kB
2
Indexable
Never
#include <stdio.h>
#include <string.h>

int main(){
    char s[1001];
    char k[] = "underconstruction";
    char name[100][31];

    int len = strlen(k), index = 0, mode = 0;

    const char *d = ":,";
    while(gets(s) != NULL){
        char *p;
        p = strtok(s, d);
        mode = 0;
        while(p != NULL){
            if(mode == 0) strcpy(name[index], p);
            if(mode == 1){
                int j = 0;
                for(int i = 0; i < strlen(p); i++){
                    if(p[i] == k[j] || p[i] == (k[j]+'A'-'a') || p[i] == (k[j]+'a'-'A')){
                        j++;
                        if(j == len) index++;
                    }
                    else if(j != 0 && j != 5 && (p[i] != k[j] && p[i] != (k[j]+'A'-'a') && p[i] != (k[j]+'a'-'A'))) j = 0;
                    //j!=5是為了讓他under construction中間有沒有空白都沒差
                }
            }
            p = strtok(NULL, d);
            if(mode == 1) mode = 0;
            else mode = 1;
        }
    }
    char tmp[100][31];
    for(int i = 0; i < index; i++){//把名字最前面讀到的空格去掉
        if(name[i][0] == ' '){
            strncpy(tmp[i], name[i]+1, strlen(name[i]));
        }
        else{
            strcpy(tmp[i], name[i]);
        }
    }
    int check = 0, ans[101];
    for(int i = 0; i < index; i++){
        ans[i] = i;
    }
    for(int i = 0; i < index; i++){//把重複的地方去掉
        for(int j = 0; j < index; j++){
            if(i == j) continue;
            if(ans[j] == -1 && strcmp(tmp[i], tmp[j]) == 0){
                check = 1;
            }
        }
        if(check == 0){
            printf("%s\n", tmp[i]);
            ans[i] = -1;
        }
        else check = 0;
    }
}