Jump to content
Terchea

problema informatica

Recommended Posts

  • Active Members
Posted

Parcurgi matricea in spirala, apoi pui elementele intr-un alt vector. Dupa ce ai pus elementele in vector verifici daca ele sunt in progresie sau nu.

Posted

#include<fstream>

using namespace std;

ifstream f("spirala.in");

ofstream g("spirala.out");

int a[101][101],n,m,x[10201],nrt;

void cit(int a[101][101],int &n, int&m)

{

f>>n>>m;

for(i=1;i<=n;i++)

for(j=1;j<=m;j++)

f>>a[j];

}

void fv(int n, int m)

{

if(n<m)nrt=n/2;

else nrt=m/2;

}

int rez(int a[][],int n, int m)

{

int i ,j, r=a[1][2]-a[1][1],t,Ok=1;

for(t=1;t>=n-t+1&&Ok;t++)

{

for(j=t;j<=m-t+1;j++)

if(a[t][j+1]-a[t][j]!=r)

Ok=0;

for(i=t;i<=n-t+1;i++)

if(a[i+1][t]-a[t]!=r)

Ok=0;

for(j=m-t+1;j>=t;j--)

if(a[n-t+1][j+1]-a[n-t+1][j]!=r)

Ok=0;

for(i=n-t+1;i>=t;i--)

if(a[i+1][m-t+1]-a[m-t+1]!=r)

Ok=0;

}

if(Ok)

return a[nrt][n-t+1];

else return Nu;

}

int main()

{

cit(a[][],n,m);

fv(n,m);

rez(a[][],n,m);

return 0;

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...