UVa - 621 Secret Research

#include<stdio.h>
#include<string.h>

char s[2000];
int n,l,c;

inline int plus() {   return !strcmp(s, "1") || !strcmp(s, "4") || !strcmp(s, "78"); }

inline int minus() {   return s[l - 2] == '3' && s[l - 1] == '5'; }

inline int star() {   return s[0] == '9' && s[l - 1] == '4'; }


int main() {

    char r[]="+-*";
    int (*pattern[3])()={plus,minus,star};

//        freopen("input.txt","r",stdin);
//        freopen("output.txt","w",stdout);   

    scanf("%d",&n);
    while(n--){
        scanf("%s",s);
        l=strlen(s);

        for(c=0;c<3;c++){
            if((*pattern[c])()) {printf("%c\n",r[c]);break;}
        }

        if(c==3) printf("?\n");
    }
    return 0;
}

No comments:

Post a Comment