Advertisement
iasmina_sarac

Untitled

Apr 13th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3. #include <iostream>
  4. using namespace std;
  5. ifstream fin("tinta.in");
  6. ofstream fout("tinta.out");
  7. vector< vector<int> > a;
  8. int suma(int i,int j)
  9. {
  10. int s=a[i][j+1]+a[i][j-1]+a[i+1][j]+a[i-1][j]+a[i-1][j-1]+a[i+1][j-1]+a[i+1][j+1]+a[i-1][j+1];
  11. return s;
  12. }
  13. int main()
  14. {
  15. int n,i=1,j=1,x=1,s;
  16. vector<int> temp;
  17.  
  18. fin>>n;
  19.  
  20. for(i=0; i<=n; i++)
  21. {
  22. temp.clear();
  23. for(j=0; j<=n; j++)
  24. temp.push_back(-1);
  25. temp.push_back(0);
  26. temp.push_back(0);
  27. a.push_back(temp);
  28. }
  29.  
  30. temp.clear();
  31.  
  32. for(j = 0; j <= n; j++)
  33. temp.push_back(0);
  34. a.push_back(temp);
  35.  
  36. temp.clear();
  37.  
  38. for(j = 0; j <= n; j++)
  39. temp.push_back(0);
  40. a.push_back(temp);
  41.  
  42. i=1;
  43. j=1;
  44.  
  45. // cerr << "ok1\n";
  46.  
  47. while(i+j<=n+1)
  48. {
  49. if((i+j)%2)
  50. {
  51. for(s=1; s<=i+j-1; s++)
  52. a[i++][j--]=x++;
  53. j++;
  54. }
  55. else
  56. {
  57. for(s=1; s<=i+j-1; s++)
  58. a[i--][j++]=x++;
  59. i++;
  60. }
  61. }
  62.  
  63. // cerr << "ok2\n";
  64.  
  65. x--;
  66. while(i+j<=2*n)
  67. {
  68. cerr << i << ' ' << j << ' ' << x << '\n';
  69. if((i+j)%2)
  70. {
  71. for(s=1; s<=i+j-1; s++)
  72. {
  73. a[i++][j--]=x++;
  74.  
  75. if(a[i][j]==0)
  76. break;
  77. }
  78. j++;
  79. x--;
  80. }
  81. else
  82. {
  83. for(s=1; s<=i+j-1; s++)
  84. {
  85. a[i--][j++]=x++;
  86. if(a[i][j]==0)
  87. break;
  88. }
  89. x--;
  90. i++;
  91. }
  92. }
  93.  
  94. // cerr << "ok3\n";
  95.  
  96. for(i=1; i<=n; i++)
  97. {
  98. for(j=1; j<=n; j++)
  99. fout<<a[i][j]<<' ';
  100. fout<<endl;
  101. }
  102. fout<<n+n-5<<endl;
  103. for(j=2; j<=n-1; j++)
  104. fout<<suma(2,j)<<' ';
  105. for(i=3; i<=n-1; i++)
  106. fout<<suma(i,n-1)<<' ';
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement