rotti321

spirala pbinfo

Dec 1st, 2021
694
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include<fstream>
  3. using namespace std;
  4. ifstream f("spirala.in");
  5. ofstream g("spirala.out");
  6. int n,a[101][101],i,j,k;
  7. int main()
  8. {
  9.     f>>n;
  10.     for(i=1;i<=n;i++)
  11.         for(j=1;j<=n;j++)
  12.             f>>a[i][j];
  13.     for(k=1;k<=n/2;k++)
  14.     {
  15.         for(j=k;j<=n-k+1;j++)
  16.             g<<a[k][j]<<" ";
  17.         for(i=k+1;i<=n-k+1;i++)
  18.             g<<a[i][n-k+1]<<" ";
  19.        for(j=n-k;j>=k;j--)
  20.         g<<a[n-k+1][j]<<" ";
  21.        for(i=n-k;i>=k+1;i--)
  22.         g<<a[i][k]<<" ";
  23.     }
  24.     if(n%2!=0)
  25.         g<<a[n/2+1][n/2+1];
  26.     return 0;
  27. }
RAW Paste Data