fork(5) download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. #define T_SIZE 1001
  7.  
  8. char* string_merge(char *, char *);
  9.  
  10. int main(){
  11. int t,n;
  12. char S1[T_SIZE], S2[T_SIZE], *S;
  13.  
  14. cin >> t; /* wczytaj liczbę testów */
  15. cin.getline(S1,T_SIZE);
  16.  
  17. while(t){
  18. cin.getline(S1,T_SIZE,' ');
  19. cin.getline(S2,T_SIZE);
  20.  
  21. S=string_merge(S1,S2);
  22. cout << S << endl;
  23. //delete[] S;
  24. t--;
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30. char* string_merge(char* s1, char* s2) {
  31.  
  32. char merged[T_SIZE * 2 - 1];
  33.  
  34. int j = 0;
  35.  
  36. for(int i = 0; i < T_SIZE; i++) {
  37.  
  38. if(!s1[i] || !s2[i]) {
  39. break;
  40. }
  41.  
  42. merged[j] = s1[i];
  43. j++;
  44.  
  45. merged[j] = s2[i];
  46. j++;
  47.  
  48. }
  49. merged[j] = '\0';
  50.  
  51. return merged;
  52.  
  53. }
Success #stdin #stdout 0s 3412KB
stdin
4
a bb
abs sfd
ewr w
wqeqweqweq eqweqwe
stdout
Standard output is empty