Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- int main()
- {
- char res[11];
- int t1,t2,a,y,b,c,x;
- char MIMEtype[9999][11],extension[9999][51];
- int N; // Number of elements which make up the association table.
- scanf("%d", &N); fgetc(stdin);
- int Q; // Number Q of file names to be analyzed.
- scanf("%d", &Q); fgetc(stdin);
- for (int i = 0; i < N; i++) {
- char EXT[11]; // file extension
- char MT[501]; // MIME type.
- scanf("%s%s", EXT, MT); fgetc(stdin);
- t1=strlen(EXT);
- t2=strlen(MT);
- //printf("%d %d\n",t1,t2);
- for (int j=0;j<t1;j++)
- MIMEtype[i][j]=EXT[j];
- for (int j=0;j<t2;j++)
- extension[i][j]=MT[j];
- }
- for (int i = 0; i < Q; i++) {
- char FNAME[501]; // One file name per line.
- fgets(FNAME,500,stdin); // One file name per line.
- int tam,temp=0;
- tam=strlen(FNAME);
- char *pos;
- int l;
- //printf("%d\n",tam);
- for (l=0;l<tam-1;l++)
- if (((int)FNAME[l])==46) break;
- //printf("%d\n",l);
- if (l!=tam-1){
- pos=strrchr(FNAME,'.')+1;
- //printf("%s",pos);
- if(strlen(pos)!=1)a=tam-strlen(pos);
- else a=0;
- }
- else a=0;
- if (a==0) printf("UNKNOWN\n");
- else {for(int c=0;c<strlen(pos)-1;c++){
- //printf("%c\n",FNAME[tam-strlen(pos)+c]);
- res[c]=FNAME[tam-strlen(pos)+c];temp++;}
- for(x=0;x<N;x++){
- for(y=0;y<temp;y++){
- //printf("%d %d\n",(int)res[y],(int)MIMEtype[x][y]);
- if( (((int)res[y])!=((int)MIMEtype[x][y])) && (((int)res[y]+32)!=((int)MIMEtype[x][y]))&&(((int)res[y]-32)!=((int)MIMEtype[x][y])) )
- break;
- }
- if (y==temp) break;
- }
- //printf("%d\n",x);
- if (x==N) printf("UNKNOWN\n");
- else printf("%s\n",extension[x]);
- }
- }
- // Write an action using printf(). DON'T FORGET THE TRAILING \n
- // To debug: fprintf(stderr, "Debug messages...\n");
- // For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement