Witam ,
Bardzo proszę o pomoc, nie wiem czemu sędzia wyrzuca błąd odpowiedzi.
Test na podsatwie przykładu z zadania wychodzi poprawnie.
#include
#include <stdlib.h>
#include <math.h>
#include <string.h>
using namespace std;
char* stringMerge(char* str1,char *str2)
{
int dlstr1 = 0, dlstr2 = 0, dlnowy = 0;
dlstr1 = strlen(str1);
dlstr2 = strlen(str2);
if (dlstr1 <= dlstr2)
dlnowy = dlstr1;
else dlnowy = dlstr2;
char *nowyString ;
dlnowy = 2*dlnowy;
nowyString = new char [dlnowy+1];
//cout << "dlugosc: "<<dlnowy<< endl;
int i=0,j=0;
do
{
nowyString[i] = str1[j];
i++;
j++;
nowyString[i] = str2[j-1];
i++;
}while(i<dlnowy);
//nowyString[dlnowy] = '/0';
// cout << "ostatni "<<nowyString[dlnowy] << endl;
return nowyString;
}
string napis1, napis2;
int main()
{
char *nowySTR;
int ilosc_testow;
string *tabwynikow;
// cout << "podaj ilosc testow : "<< endl;
cin>>ilosc_testow;
tabwynikow = new string[ilosc_testow];
for(int i=0; i<ilosc_testow;i++)
{
//cout << "podaj stringi "<< endl;
cin>>napis1>>napis2;
nowySTR = stringMerge(&napis1[0], &napis2[0]);
tabwynikow[i] = nowySTR;
// delete [] nowySTR;
}
for(int i=0;i<ilosc_testow;i++)
{
cout<<tabwynikow[i]<<endl;
}
delete [] tabwynikow;
return 0;
}