Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin ("teza.in");
  6. ofstream fout ("teza.out");
  7.  
  8. int n, a[100][100]={3};
  9.  
  10. void tiparireMatrice (int i, int j)
  11. {
  12. for (i=1; i<=n; i++)
  13. {
  14. for (j=1; j<=n; j++)
  15. fout << a[i][j] << ' ';
  16. fout << '\n';
  17. }
  18. }
  19.  
  20. void parcurgereMatrice (int i, int j)
  21. {
  22. if (i<=n)
  23. {
  24. for (j=1; j<=n; j++)
  25. fout << a[i][j] << ' ';
  26. fout << '\n';
  27. for (j=n; j; j--)
  28. fout << a[i][j] << ' ';
  29. fout << '\n';
  30. parcurgereMatrice(i+2, j);
  31. }
  32. }
  33.  
  34. void constr (int i)
  35. {
  36. if (i<=n)
  37. {
  38. a[i][i]=2;
  39. a[i][n+1-i]=2;
  40. constr(i+1);
  41. }
  42. }
  43.  
  44. void construireMatrice (int i, int j)
  45. {
  46. if (i<=n)
  47. {
  48. if (j<=n)
  49. {
  50. if ((i<j && i+j>n+1) || (i<j && i+j<=n))
  51. a[i][j]=3;
  52. if (!a[i][j])
  53. a[i][j]=4;
  54. construireMatrice(i, j+1);
  55. }
  56. j=1;
  57. construireMatrice(i+1, j);
  58. }
  59. constr(1);
  60. a[(n+1)/2][(n+1)/2]=1;
  61. }
  62.  
  63. int main ()
  64. {
  65. fin >> n;
  66. int i, j;
  67. construireMatrice(1, 1);
  68. tiparireMatrice(i, j);
  69. fout << '\n';
  70. parcurgereMatrice (1, j);
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement