标签:输入 接下来 长度 翻转 nbsp style scan ring 顺时针
给定m行n列的图像各像素点灰度值,对其依次进行一系列操作后,求最终图像。
其中,可能的操作及对应字符有如下四种:
A:顺时针旋转90度;
B:逆时针旋转90度;
C:左右翻转;
D:上下翻转。
2 3 10 0 10 100 100 10 AC
10 100 0 100 10 10
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 char c; 5 int a[110][110]; 6 void A(int a[][110],int &m,int &n) 7 { 8 int b[110][110],p; 9 for(int i=0;i<m;i++) 10 { 11 for(int j=0;j<n;j++) 12 b[j][m-i-1]=a[i][j]; 13 } 14 p=m; 15 m=n; 16 n=p; 17 memset(a,0,sizeof(a)); 18 memcpy(a,b,sizeof(b)); 19 } 20 void B(int a[][110],int &m,int &n) 21 { 22 A(a,m,n); 23 A(a,m,n); 24 A(a,m,n); 25 } 26 void C(int a[][110],int &m,int &n) 27 { 28 int b[110][110],p; 29 for(int i=0;i<m;i++) 30 { 31 for(int j=0;j<n;j++) 32 b[i][j]=a[i][n-j-1]; 33 } 34 memset(a,0,sizeof(a)); 35 memcpy(a,b,sizeof(b)); 36 } 37 void D(int a[][110],int &m,int &n) 38 { 39 int b[110][110],p; 40 for(int i=0;i<m;i++) 41 for(int j=0;j<n;j++) 42 b[i][j]=a[m-i-1][j]; 43 memset(a,0,sizeof(a)); 44 memcpy(a,b,sizeof(b)); 45 } 46 int main() 47 { 48 int n,m; 49 scanf("%d %d",&m,&n); 50 for(int i=0;i<m;i++) 51 for(int j=0;j<n;j++) 52 scanf("%d",&a[i][j]); 53 while(scanf("%c",&c)==1) 54 { 55 if(c==‘A‘)A(a,m,n); 56 if(c==‘B‘)B(a,m,n); 57 if(c==‘C‘)C(a,m,n); 58 if(c==‘D‘)D(a,m,n); 59 } 60 for(int i=0;i<m;i++) 61 { 62 for(int j=0;j<n;j++) 63 printf("%d ",a[i][j]); 64 if(i!=m-1)printf("\n"); 65 } 66 return 0; 67 }
标签:输入 接下来 长度 翻转 nbsp style scan ring 顺时针
原文地址:http://www.cnblogs.com/zby-ccsygz/p/6158886.html