Advertisement
Guest User

MIME type (noob)

a guest
Nov 24th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.50 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. /**
  6.  * Auto-generated code below aims at helping you parse
  7.  * the standard input according to the problem statement.
  8.  **/
  9. int main()
  10. {
  11.    char res[11];
  12.     int t1,t2,a,y,b,c,x;
  13.     char MIMEtype[9999][11],extension[9999][51];
  14.    
  15.     int N; // Number of elements which make up the association table.
  16.     scanf("%d", &N); fgetc(stdin);
  17.     int Q; // Number Q of file names to be analyzed.
  18.     scanf("%d", &Q); fgetc(stdin);
  19.     for (int i = 0; i < N; i++) {
  20.         char EXT[11]; // file extension
  21.         char MT[501]; // MIME type.
  22.         scanf("%s%s", EXT, MT); fgetc(stdin);
  23.         t1=strlen(EXT);
  24.         t2=strlen(MT);
  25.         //printf("%d %d\n",t1,t2);
  26.         for (int j=0;j<t1;j++)
  27.         MIMEtype[i][j]=EXT[j];
  28.         for (int j=0;j<t2;j++)
  29.         extension[i][j]=MT[j];
  30.     }
  31.    
  32.     for (int i = 0; i < Q; i++) {
  33.         char FNAME[501]; // One file name per line.
  34.         fgets(FNAME,500,stdin); // One file name per line.
  35.         int tam,temp=0;
  36.         tam=strlen(FNAME);
  37.         char *pos;
  38.         int l;
  39.         //printf("%d\n",tam);
  40.         for (l=0;l<tam-1;l++)
  41.             if (((int)FNAME[l])==46) break;
  42.         //printf("%d\n",l);
  43.         if (l!=tam-1){
  44.         pos=strrchr(FNAME,'.')+1;
  45.         //printf("%s",pos);
  46.         if(strlen(pos)!=1)a=tam-strlen(pos);
  47.             else a=0;
  48.         }
  49.         else a=0;
  50.        
  51.         if (a==0) printf("UNKNOWN\n");
  52.         else {for(int c=0;c<strlen(pos)-1;c++){
  53.                 //printf("%c\n",FNAME[tam-strlen(pos)+c]);
  54.                res[c]=FNAME[tam-strlen(pos)+c];temp++;}
  55.                
  56.               for(x=0;x<N;x++){
  57.                   for(y=0;y<temp;y++){
  58.                       //printf("%d %d\n",(int)res[y],(int)MIMEtype[x][y]);
  59.                     if( (((int)res[y])!=((int)MIMEtype[x][y])) && (((int)res[y]+32)!=((int)MIMEtype[x][y]))&&(((int)res[y]-32)!=((int)MIMEtype[x][y])) )
  60.                         break;
  61.                   }
  62.                 if (y==temp) break;
  63.               }
  64.               //printf("%d\n",x);
  65.               if (x==N) printf("UNKNOWN\n");
  66.                 else printf("%s\n",extension[x]);
  67.                        
  68.             }
  69.     }
  70.  
  71.     // Write an action using printf(). DON'T FORGET THE TRAILING \n
  72.     // To debug: fprintf(stderr, "Debug messages...\n");
  73.  
  74.     // For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement