llllmz

导航

KY146 魔咒词典C

#include<stdio.h>
#include<string.h>
struct node{
    char a[100];
    char b[100];
};
typedef struct node dir;
dir s[100000];

int main(){
    char A[200];
    int top=0;
    while(gets(A)){//建立字典
        if(A[0]=='@') break;
        int i=0;
        for(;A[i]!='\0';i++){
            if(A[i]==']'){
                break;
            }
        }
        for(int j=0;j<=i;j++){
            s[top].a[j]=A[j];
        }
        for(int j=i+2;A[j]!='\0';j++){
            s[top].b[j-i-2]=A[j];
        }
        top++;
    }
    int n;
    scanf("%d",&n);
    char c;
    c=getchar();//读入换行
    while(n!=0){//查字典
        char tem[100];
        gets(tem);
        int i=0;
        for(;i<top;i++){
            if(strcmp(s[i].a,tem)==0){
                printf("%s\n",s[i].b);
                break;
            }else if(strcmp(s[i].b,tem)==0){
                char x[100]={'\0'};
                for(int j=1;s[i].a[j]!=']';j++){
                    x[j-1]=s[i].a[j];
                }
                printf("%s\n",x);
                break;
            }
        }
        if(i==top) printf("what?\n");
        n--;
    }

    return 0;
}

结果如下:

 

posted on 2024-01-30 20:25  神奇的萝卜丝  阅读(62)  评论(0)    收藏  举报