fork(3) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n;
  5.  
  6. int main()
  7. {
  8.  
  9. cin>>n;
  10. int tab[n];
  11. if(n>2)
  12. {
  13. for(int i=0; i<=n/2; i++)
  14. {
  15. tab[i]=i;
  16. }
  17. for( int j=n; j>n/2; j--)
  18. {
  19. tab[j]=j;
  20. }
  21.  
  22. if(n%2!=0)
  23. {
  24. for( int j=n-1; j>n/2; j-=2)
  25. {
  26. cout<<tab[j]<<" ";
  27. }
  28. for( int i=0; i<=n/2; i+=2)
  29. {
  30. cout<<tab[i]<<" ";
  31. }
  32. for( int j=n; j>n/2; j-=2)
  33. {
  34. cout<<tab[j]<<" ";
  35. }
  36. for( int i=1; i<=n/2; i+=2)
  37. {
  38. cout<<tab[i]<<" ";
  39. }
  40.  
  41.  
  42. }
  43. else
  44. {
  45. for( int i=0; i<=n/2; i+=2)
  46. {
  47. cout<<tab[i]<<" ";
  48. }
  49. for( int j=n; j>n/2; j-=2)
  50. {
  51. cout<<tab[j]<<" ";
  52. }
  53. for( int i=1; i<=n/2; i+=2)
  54. {
  55. cout<<tab[i]<<" ";
  56. }
  57. for( int j=n-1; j>n/2; j-=2)
  58. {
  59. cout<<tab[j]<<" ";
  60. }
  61. }
  62. }
  63. else cout<<"NIE";
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. return 0;
  72. }
  73.  
Success #stdin #stdout 0.01s 3464KB
stdin
3
stdout
2 0 3 1