Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- int n, m, i , j, tmp;
- cin >> n >> m;
- if ( n > m){
- tmp = m;
- }else{
- tmp = n;
- }
- int a[n][m];
- int lane;
- int start_lane = 0;
- int end_lane = n-1;
- int start_column = 0;
- int end_column = m-1;
- int numb = 1;
- for ( lane = 0; lane < (2*tmp); lane++){
- if ( lane%4 == 0){
- for ( j = start_column; j < end_column+1; j++){
- i = start_lane;
- a[i][j] = numb;
- numb++;
- //cout << i << j<<" ";
- //cout << setw(4)<<a[i][j];
- }
- start_lane++;//0+1 = 1
- //cout << endl;
- }else if ( lane%4 == 1){
- for ( i = start_lane; i < end_lane+1; i++){
- j = end_column;
- a[i][j] = numb;
- numb++;
- //cout << i << j<<" ";
- //cout << setw(4)<<a[i][j];
- }
- end_column--; // (m-1)-1
- //cout << endl;
- }else if ( lane%4 == 2){
- for ( j = end_column; j > start_column-1; j--){
- i = end_lane;
- a[i][j] = numb;
- numb++;
- //cout << i << j<<" ";
- //cout << setw(4)<<a[i][j];
- }
- end_lane--; //(n-1)-1
- //cout << endl;
- }else if ( lane%4 == 3){
- for ( i = end_lane; i > start_lane-1; i--){
- j = start_column;
- a[i][j] = numb;
- numb++;
- //cout << i << j<<" ";
- //cout << setw(4)<<a[i][j];
- }
- start_column++;// 0+1 = 1
- // cout << endl;
- }
- }
- // ВЫВОД
- for ( i=0; i < n; i++){
- for ( j= 0; j< m; j++){
- cout << setw(4) << a[i][j];
- }
- cout<<endl;
- }
- // put your code here
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement