The problem _fun of rotating square matrix

Source: Internet
Author: User

#include <iostream>
#include <stdlib.h>
#define LEN 20

void fun1 (int (&a) [Len][len],int N)
{
int i,j,m;
int s,t;
t=0;
M=N/2;
if (n%2==1) a[m+1][m+1]=n*n;
for (i=1;i<=m;i++)
{
s=n-2*i+1;
for (j=i;j<=n-i;j++)
{
A[i][j]=t+1-i+j;
A[j][n+1-i]=t+1-i+j+s;
A[n+1-i][j+1]=t+3*s-j+i;
A[j+1][i]=t+4*s-j+i;
}
t+=4*s;
}
}


void fun2 (int (&a) [Len][len],int N)
{
int i,j,m;
int s,t;
t=0;
M=N/2;
if (n%2==1) a[m+1][m+1]=n*n;
for (i=1;i<=m;i++)
{
s=n-2*i+1;
for (j=i;j<=n-i;j++)
{
A[j][i]=t+1-i+j;
A[n+1-i][j]=t+1-i+j+s;
A[j+1][n+1-i]=t+3*s-j+i;
A[i][j+1]=t+4*s-j+i;
}
t+=4*s;
}

}




void Fun3 (int (&a) [Len][len],int N)
{
int i,j,m;
int s,t;
t=0;
M=N/2;
if (n%2==1) a[m+1][m+1]=n*n;
for (i=1;i<=m;i++)
{
s=n-2*i+1;
for (j=i;j<=n-i;j++)
{
if (i%2)
{
A[i][j]=t+1-i+j;
A[j][n+1-i]=t+1-i+j+s;
A[n+1-i][j+1]=t+3*s-j+i;
A[j+1][i]=t+4*s-j+i;
}
Else
{a[j][i]=t+1-i+j;
A[n+1-i][j]=t+1-i+j+s;
A[j+1][n+1-i]=t+3*s-j+i;
A[i][j+1]=t+4*s-j+i;
}
}
t+=4*s;
}
}


void Fun4 (int (&a) [Len][len],int N)
{
int i,j,m;
int s,t;
t=0;
M=N/2;
if (n%2==1) a[m+1][m+1]=n*n;
for (i=1;i<=m;i++)
{
s=n-2*i+1;
for (j=i;j<=n-i;j++)
{
if (i%2==0)
{
A[i][j]=t+1-i+j;
A[j][n+1-i]=t+1-i+j+s;
A[n+1-i][j+1]=t+3*s-j+i;
A[j+1][i]=t+4*s-j+i;
}
Else
{a[j][i]=t+1-i+j;
A[n+1-i][j]=t+1-i+j+s;
A[j+1][n+1-i]=t+3*s-j+i;
A[i][j+1]=t+4*s-j+i;
}
}
t+=4*s;
}
}


int main (int argc, char *argv[])
{
int I,j,n,a[len][len];
int p; E for tag selection actions
cout<< "1: cis-turn N-order Square" <<endl
<< "2: Reversing N-order Phalanx" <<endl
<< "3: Shun reversed Phalanx" <<endl
<< "4: Inverse cis-square square" <<endl;
cout<< "Please input your phalanx selection:" <<endl;
cin>>p;
cout<< "Enter your Phalanx number n:" <<endl;
cin>>n;
Switch (p)
{
Case 1:FUN1 (a,n); cout<< "cis-N-order Phalanx" <<endl; Break
Case 2:fun2 (a,n);cout<< "cis-N-order Phalanx" <<endl; Break
Case 3:fun3 (a,n);cout<< "Shun reversed N-order Phalanx" <<endl; Break
Case 4:fun4 (a,n);cout<< "Inverse cis-n-order matrix" <<endl; Break
}
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
cout<<a[i][j]<< "";
cout<<endl;
}
System ("PAUSE");
return 0;
}

The four basic ideas are consistent, just because the time relationship, has not been a concise correction, appears particularly verbose, the next time to make corrections.

In a hurry, we have to go to the meeting.

Where I refers to the number of circles in which the square is turned, J represents the operation of the n-2*i+1 element on the edge of the circle number I.

The operation of CIS and reversal is only to interchange the ranks,

The odd-loop operation of CIS-CIS matrix is operated by inverse operation. Even circle with reversed square.

The reverse operation is interchangeable with CIS operation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.