poj 3752 字母旋转游戏
字母旋转游戏
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7890 | Accepted: 2983 |
Description
给定两个整数M,N,生成一个M*N的矩阵,矩阵中元素取值为A至Z的26个字母中的一个,A在左上角,其余各数按顺时针方向旋转前进,依次递增放置,当超过26时又从A开始填充。例如,当M=5,N=8时,矩阵中的内容如下:
A B C D E F G H
V W X Y Z A B I
U J K L M N C J
T I H G F E D K
S R Q P O N M L
Input
M为行数,N为列数,其中M,N都为大于0的整数。
Output
分行输出相应的结果
Sample Input
4 9
Sample Output
A B C D E F G H I V W X Y Z A B C J U J I H G F E D K T S R Q P O N M L
Source
分析:
模拟
1 #include<iostream> 2 #include<queue> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 char map[1005][1005],c[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; 8 int main(){ 9 int m,n; 10 cin>>m>>n; 11 int i,j,x=1,y=0; 12 memset(map,'0',sizeof(map)); 13 int sum=m*n; 14 //cout<<m<<' '<<n<<endl; 15 i=0; 16 for(;i<sum;){ 17 while(y+1<=n&&map[x][y+1]=='0'){ 18 y++; 19 //cout<<"i: "<<i<<endl; 20 map[x][y]=c[i%26]; 21 i++; 22 } 23 // cout<<1<<endl; 24 while(x+1<=m&&map[x+1][y]=='0'){ 25 x++; 26 //i++; 27 //cout<<"i: "<<i<<endl; 28 map[x][y]=c[i%26]; 29 i++; 30 } 31 // cout<<2<<endl; 32 while(y-1>0&&map[x][y-1]=='0'){ 33 y--; 34 //i++; 35 // cout<<"i: "<<i<<endl; 36 map[x][y]=c[i%26]; 37 i++; 38 } 39 // cout<<3<<endl; 40 while(x-1>0&&map[x-1][y]=='0'){ 41 x--; 42 //i++; 43 // cout<<"i: "<<i<<endl; 44 map[x][y]=c[i%26]; 45 i++; 46 } 47 // cout<<4<<endl; 48 } 49 //cout<<m<<' '<<n<<endl; 50 for(i=1;i<=m;i++){ 51 for(j=1;j<=n;j++){ 52 cout<<" "<<map[i][j]; 53 //A B C D E F G H 54 } 55 cout<<endl; 56 } 57 return 0; 58 }