Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <cstring>
- using namespace std;
- char* StringMerge(char* napis1_, char* napis2_)
- {
- int dlugosc_napis1, dlugosc_napis2;
- char* nowy_napis;
- dlugosc_napis1 = strlen(napis1_);
- dlugosc_napis2 = strlen(napis2_);
- //napis1_[dlugosc_napis1] = '\0';
- //napis2_[dlugosc_napis2] = '\0';
- if (dlugosc_napis1 >= dlugosc_napis2)
- {
- nowy_napis = new char[(dlugosc_napis2 * 2) +1];
- for (int i = 0; i < dlugosc_napis2 * 2; ++i)
- {
- if (i % 2 == 0)
- nowy_napis[i] = napis1_[i / 2];
- else
- nowy_napis[i] = napis2_[i / 2];
- }
- nowy_napis[dlugosc_napis2*2] = '\0';
- }
- else
- {
- nowy_napis = new char[(dlugosc_napis1 * 2) +1];
- for (int i = 0; i < dlugosc_napis1 * 2; ++i)
- {
- if (i % 2 == 0)
- nowy_napis[i] = napis1_[i/2];
- else
- nowy_napis[i] = napis2_[i/2];
- }
- nowy_napis[dlugosc_napis1 * 2] = '\0';
- }
- return nowy_napis;
- }
- int main()
- {
- int ile;
- char napis1[100], napis2[100];
- char* nowy_napis;
- //cout << "Podaj ile testow: ";
- cin >> ile;
- if (ile > 0)
- {
- for (int i = 0; i < ile; ++i)
- {
- cin >> napis1;
- cin >> napis2;
- nowy_napis=StringMerge(napis1, napis2);
- cout << nowy_napis << endl;
- delete[] nowy_napis;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement