Monday, February 24, 2014

codechef FEB14 LCPESY - Longest Common Pattern solution

codechef February 2014 Challenge FEB14 LCPESY - Longest Common Pattern: http://www.codechef.com/problems/LCPESY

codechef FEB14 LCPESY - Longest Common Pattern solution: http://www.codechef.com/viewsolution/3383472
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main() {
  7. int t, cnt, a[100], b[100];
  8. char s1[10005], s2[10005];
  9. scanf("%d", &t);
  10. while(t--) {
  11. cnt=0;
  12. for(int i=0; i<100; i++) a[i]=b[i]=0;
  13. scanf("%s\n%s", s1, s2);
  14. for(int i=0; i<strlen(s1); i++) a[s1[i]-48]++;
  15. for(int i=0; i<strlen(s2); i++) b[s2[i]-48]++;
  16. for(int i=0; i<100; i++) {
  17. if(a[i]<b[i]) cnt += a[i];
  18. else cnt += b[i];
  19. }
  20. printf("%d\n", cnt);
  21. }
  22. return 0;
  23. }

note: memset() gave TLE


No comments:

Post a Comment