fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_LENGTH = 2000;
  6.  
  7. int main() {
  8. char a[MAX_LENGTH], b[MAX_LENGTH];
  9. cin.getline(a,MAX_LENGTH);
  10. cin.getline(b,MAX_LENGTH);
  11. int lengthA = strlen(a);
  12. int lengthB = strlen(b);
  13. char *p = strstr(a, b);
  14.  
  15. //cout << lengthA <<" " << lengthB;
  16.  
  17. if (strcmp(a,b) == 0) {
  18. cout <<a << b;
  19. }
  20.  
  21. while (p != 0) {
  22. cout << p - a;
  23. p = strstr(p + 1, b );
  24. }
  25. if (p == 0) {
  26. for ( int i = 0; i < (lengthA + lengthB); ++i) {
  27. cout << a[i] << b[i];
  28. }
  29. }
  30. cout << p;
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5320KB
stdin
abc
defgh
stdout
adbecfgh