codechef MIME2 - "internet media types" editorial : http://discuss.codechef.com/questions/4156/mime2-editorial
codechef MIME2 - "internet media types" solution : http://ideone.com/BpkSuR
#include <iostream>#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int n, q, dot, index, flag;
char s[105][55], e[105][55], a[55], b[55], tmp[55];
scanf("%d%d", &n, &q);
for(int i=0; i<n; i++) scanf("%s%s", s[i], e[i]);
while(q--) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(tmp, 0, sizeof(tmp));
dot=0;
flag=0;
index=0;
scanf("%s", a);
for(int i=0; i<strlen(a); i++) {
if(a[strlen(a)-1-i]=='.') {
dot=1;
break;
}
tmp[i]=a[strlen(a)-1-i];
}
if(dot) {
for(int i=0; i<strlen(tmp); i++) {
b[i]=tmp[strlen(tmp)-1-i];
}
for(int i=0; i<n; i++) {
if(strcmp(b, s[i])==0) {
flag=1;
index=i;
break;
}
}
if(flag) printf("%s\n", e[index]);
else printf("unknown\n");
}
else printf("unknown\n");
}
return 0;
}
note: n lines entered two strings, 1st is extension, 2nd is file type. and then q lines user inputs media names. coders task is to check if there exist any extension at any given file name, if no coder outputs "unknown", if yes, coder now seeks for same extension's file type through saved file extensions and types char array. if coder finds any equivalent file type for existing extension, then he outputs corresponding file type, if vice versa, he then outputs "unknown"
No comments:
Post a Comment