fork download
  1. //Little Elephant and Strings
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <string>
  5. using namespace std;
  6. string pill,good[50];
  7. bool substring(string s1,string s2)
  8. {
  9. cout<<"S1:: "<<s1<<endl;
  10. cout<<"S2:: "<<s2<<endl;
  11. cout<<"s1 Length:"<<s1.length()<<endl;
  12. cout<<"s2 Length:"<<s2.length()<<endl;
  13. int lt=s1.length()-s2.length()+1;
  14. cout<<"s1.length()-s2.length()+1 "<<lt<<endl;
  15. for(int i=0;i<s1.length()-s2.length()+1;i++)
  16. {
  17. cout<<"I val is: "<<i;
  18. cout<<" .The Substring is "<<s1.string::substr(i,s2.length())<<endl;
  19. if(s1.string::substr(i,s2.length())==s2)
  20. {
  21.  
  22. return true;
  23. }
  24. }
  25. return false;
  26. }
  27. int main()
  28. {
  29. int n,k;
  30. scanf("%d %d",&n,&k);
  31. string pill,good[50];
  32. for(int i=0;i<n;i++)
  33. cin >> good[i];
  34. int boolean=0;
  35. for(int i=0;i<k;i++)
  36. {
  37. boolean=0;
  38. cin >> pill;
  39. if(pill.length()>=47)
  40. {
  41. puts("Good");
  42. boolean++;
  43. }
  44. else
  45. {
  46. for(int j=0;j<n;j++)
  47. {
  48. if (substring(pill,good[j])==true)
  49. {
  50.  
  51. puts("Good");
  52. boolean++;
  53. break;
  54. }
  55. }
  56. }
  57. if (boolean==0)
  58. puts("Bad");
  59. }
  60.  
  61. //system("pause");
  62. return 0;
  63.  
  64.  
  65.  
  66. }
Runtime error #stdin #stdout 0.01s 2864KB
stdin
1 1
74747474
47
stdout
S1:: 47
S2:: 74747474
s1 Length:2
s2 Length:8
s1.length()-s2.length()+1 -5
I val is: 0 .The Substring is 47
I val is: 1 .The Substring is 7
I val is: 2 .The Substring is 
I val is: 3