fork(6) download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. //////////////////// 주석 뗀 버전
  8.  
  9. int* buildSnailReverse(int* a, int w, int h)
  10. {
  11. int
  12. u[] = { 1, w,-1,-w},
  13. d = w < h,
  14. z = ((d? w: h) - 1 >> 1) * (w + 1) + (~w & d),
  15. n = d? h - w: w - h,
  16. p = 0,
  17. c = n,
  18. i = 0;
  19. while(i < w * h)
  20. {
  21. a[z] = ++i;
  22. z += u[d];
  23. if (!c--) ++d &= 3, c = n ^= p ^= n ^= p++;
  24. }
  25. return a;
  26. }
  27.  
  28. void printArray(int* a, int w, int h) { for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) printf("%3d", a[x + y * w]); cout << endl; } }
  29.  
  30. int main()
  31. {
  32. int w, h;
  33. cin >> w >> h;
  34. int* a = new int[w * h];
  35. buildSnailReverse(a, w, h);
  36. printArray(a, w, h);
  37. delete[] a;
  38. fflush(stdin);
  39. getchar();
  40. return 0;
  41. }
Runtime error #stdin #stdout 0s 3876KB
stdin
Standard input is empty
stdout
Standard output is empty