fork download
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. char* stringMerge(char* str1,char *str2)
  10. {
  11. int dlstr1 = 0, dlstr2 = 0, dlnowy = 0;
  12.  
  13. dlstr1 = strlen(str1);
  14. dlstr2 = strlen(str2);
  15.  
  16. if (dlstr1 <= dlstr2)
  17. dlnowy = dlstr1;
  18. else dlnowy = dlstr2;
  19.  
  20. char *nowyString ;
  21.  
  22. dlnowy = 2*dlnowy;
  23. nowyString = new char [dlnowy+1];
  24.  
  25. //cout << "dlugosc: "<<dlnowy<< endl;
  26.  
  27. int i=0,j=0;
  28.  
  29. do
  30. {
  31. nowyString[i] = str1[j];
  32. i++;
  33. j++;
  34. nowyString[i] = str2[j-1];
  35. i++;
  36. }while(i<dlnowy);
  37.  
  38. //nowyString[dlnowy] = '/0';
  39.  
  40. // cout << "ostatni "<<nowyString[dlnowy] << endl;
  41.  
  42. return nowyString;
  43. }
  44.  
  45.  
  46. string napis1, napis2;
  47.  
  48. int main()
  49. {
  50. char *nowySTR;
  51. int ilosc_testow;
  52. string *tabwynikow;
  53.  
  54. // cout << "podaj ilosc testow : "<< endl;
  55. cin>>ilosc_testow;
  56.  
  57. tabwynikow = new string[ilosc_testow];
  58.  
  59. for(int i=0; i<ilosc_testow;i++)
  60. {
  61. //cout << "podaj stringi "<< endl;
  62. cin>>napis1>>napis2;
  63. nowySTR = stringMerge(&napis1[0], &napis2[0]);
  64.  
  65. tabwynikow[i] = nowySTR;
  66. // delete [] nowySTR;
  67. }
  68.  
  69. for(int i=0;i<ilosc_testow;i++)
  70. {
  71. cout<<tabwynikow[i]<<endl;
  72. }
  73.  
  74.  
  75. delete [] tabwynikow;
  76. return 0;
  77. }
  78.  
Success #stdin #stdout 0.04s 4420KB
stdin
Standard input is empty
stdout