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 >> a >> b;
  10. // cin.getline(a,MAX_LENGTH);
  11. // cin.getline(b,MAX_LENGTH);
  12. int lengthA = strlen(a);
  13. int lengthB = strlen(b);
  14. char *p ;
  15. int flag = 1, pos = -1;
  16. if (strcmp(a, b) > 0) {
  17. p = strstr(a, b); ///
  18. while (p != 0 && flag == 1) {
  19. pos = p - a;
  20. cout << p - a;
  21. p = strstr(p + 1, b);
  22. flag = 2;
  23. }
  24. cout << "DA ";
  25. } else if (strcmp(a, b) < 0) {
  26. p = strstr(b, a); ///
  27. while (p != 0 ) {
  28. pos = p - b;
  29. cout << p - b;
  30. p = strstr(p + 1, a);
  31. flag = 3;
  32. }
  33. cout << "NU " ;
  34. }
  35. cout << pos <<"<--\n";
  36.  
  37. if (strcmp(a,b) == 0) {
  38. cout <<a << b;
  39. } else if (pos == -1){
  40. for (int i = 0; i < lengthA || i < lengthB ; ++i) {
  41. if (i > lengthA - 1 && i < lengthB ) {
  42. cout << b[i];
  43. } else if (i > lengthB - 1 && i < lengthA ) {
  44. cout << a[i];
  45. } else {
  46. cout << a[i] << b[i];
  47. // cout << a[i] << b[i]<< i <<";\n";
  48. }
  49. }
  50. } else if ( flag % 2 == 0) {
  51. cout << pos + 1 << " " << pos + lengthB ;
  52. } else {
  53. cout << pos << " " << pos + lengthA - 1;
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5320KB
stdin
asaa
sa
stdout
NU -1<--
assaaa