Advertisement
Guest User

Untitled

a guest
May 27th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. char* StringMerge(char* napis1_, char* napis2_)
  9. {
  10. int dlugosc_napis1, dlugosc_napis2;
  11. char* nowy_napis;
  12.  
  13. dlugosc_napis1 = strlen(napis1_);
  14. dlugosc_napis2 = strlen(napis2_);
  15. //napis1_[dlugosc_napis1] = '\0';
  16. //napis2_[dlugosc_napis2] = '\0';
  17.  
  18.  
  19. if (dlugosc_napis1 >= dlugosc_napis2)
  20. {
  21. nowy_napis = new char[(dlugosc_napis2 * 2) +1];
  22. for (int i = 0; i < dlugosc_napis2 * 2; ++i)
  23. {
  24. if (i % 2 == 0)
  25. nowy_napis[i] = napis1_[i / 2];
  26. else
  27. nowy_napis[i] = napis2_[i / 2];
  28. }
  29. nowy_napis[dlugosc_napis2*2] = '\0';
  30. }
  31. else
  32. {
  33. nowy_napis = new char[(dlugosc_napis1 * 2) +1];
  34. for (int i = 0; i < dlugosc_napis1 * 2; ++i)
  35. {
  36. if (i % 2 == 0)
  37. nowy_napis[i] = napis1_[i/2];
  38. else
  39. nowy_napis[i] = napis2_[i/2];
  40. }
  41. nowy_napis[dlugosc_napis1 * 2] = '\0';
  42. }
  43. return nowy_napis;
  44. }
  45.  
  46. int main()
  47. {
  48. int ile;
  49. char napis1[100], napis2[100];
  50. char* nowy_napis;
  51.  
  52. //cout << "Podaj ile testow: ";
  53. cin >> ile;
  54.  
  55. if (ile > 0)
  56. {
  57. for (int i = 0; i < ile; ++i)
  58. {
  59. cin >> napis1;
  60. cin >> napis2;
  61. nowy_napis=StringMerge(napis1, napis2);
  62. cout << nowy_napis << endl;
  63. delete[] nowy_napis;
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement