#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<iostream> //#include<algorithm> //#include <bits/stdc++.h> int main() { int m,n; scanf("%d %d",&m,&n); char num[100][100]= {'0'}; for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { num[i][j]='0'; } } int hasin=0; int tempi=0,tempj=0; while(hasin!=m*n) { while(num[tempi][tempj]=='0' && tempj<n) { num[tempi][tempj]='A'+hasin%26; hasin++; if(tempj+1<n && num[tempi][tempj+1]=='0') { tempj++; } else { break; } } tempi++; while(num[tempi][tempj]=='0' && tempi<m) { num[tempi][tempj]='A'+hasin%26; hasin++; // printf("%c",num[tempi][tempj]); if(tempi+1<m && num[tempi+1][tempj]=='0') { tempi++; } else { break; } } // printf("%d %d\n",tempi,tempj); tempj--; while(num[tempi][tempj]=='0' && tempj>=0) { num[tempi][tempj]='A'+hasin%26; hasin++; // printf("%c",num[tempi][tempj]); if(tempj-1>=0 && num[tempi][tempj-1]=='0') { tempj--; } else { break; } } // printf("%d %d\n",tempi,tempj); tempi--; while(num[tempi][tempj]=='0' && tempi>=0) { num[tempi][tempj]='A'+hasin%26; hasin++; // printf("%c",num[tempi][tempj]); if(tempi-1>=0 && num[tempi-1][tempj]=='0') { tempi--; } else { break; } } tempj++; // printf("%d %d\n",tempi,tempj); // break; } for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { printf(" %c",num[i][j]); } printf("\n"); } } |
Double click to view unformatted code.