fork(4) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define SIZE 14 //multiple of 3
  6. void arrange(char arr[], int n, int i)
  7. {
  8.  
  9. if(i == 1)
  10. {
  11. arr[1] = arr[n];
  12. //arr[2] = arr[n <<1];
  13. return;
  14. }
  15. int a = arr[i - 1];
  16. int b = arr[n + i - 1];
  17. //int c = arr[2*n + i - 1];
  18.  
  19. arrange(arr, n, i - 1);
  20.  
  21. int x = 2* (i - 1);
  22. arr[x] = a;
  23. arr[x + 1] = b;
  24. //arr[x + 2] = c;
  25. }
  26.  
  27. int main()
  28. {
  29. int n = SIZE;
  30. char a[]="a1b2c3d4";int i;
  31.  
  32. if(n != 0 && n % 2== 0)arrange(a, n/2, n/2);
  33. for(i = 0; i <n;i++)
  34. cout << a[i] << " ";
  35.  
  36.  
  37. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
a 4 1  b � 2 p c � 3 � d