codechef LUCKYSTR - "little elephant and strings" solution: http://ideone.com/DtYOZ7
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
 int k, n, flag;
 char f[55][55], s[55];
 scanf("%d%d", &k, &n); 
 for(int i=0; i<k; i++) scanf("%s", f[i]);
 for(int i=0; i<n; i++) {
  scanf("%s", s);
  flag=0;
  if(strlen(s)>=47) printf("Good\n");
  else {
   for(int j=0; j<k; j++) {
    if(strstr(s, f[j])) {
     flag=1;
     break;
    }
   }
   if(flag) printf("Good\n");
   else printf("Bad\n");
  }
 }
}
note: i was damn tired of coding bugs, when i was trying to solve this problem. add to that previous days i had failed to solve "arrange" and "equation" problems at codechef. but then i came up with "strstr" function in <cstring> header : http://en.cppreference.com/w/cpp/string/byte/strstr
 
No comments:
Post a Comment