luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/PTIT006?fbclid=IwAR2ydTa7H99Gd7M7cn8SkYmCJTYSF9P5DNOvlhWVVV_cz5WPTbCogbcWdBY #891

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Ma trận xoắn ốc 1 - Luyện Code Online

https://oj.luyencode.net/problem/PTIT006?fbclid=IwAR2ydTa7H99Gd7M7cn8SkYmCJTYSF9P5DNOvlhWVVV_cz5WPTbCogbcWdBY

NormalRandomDude commented 1 year ago

include <bits/stdc++.h>

define ll int

using namespace std; int main() { ll n; cin>>n; ll a[50][50],d=0,gt=1,hang=n-1,cot=n-1; while (d<=n/2) { for (ll i=d;i<=cot;i++) a[d][i]=gt++; for (ll i=d+1;i<=hang;i++) a[i][cot]=gt++; for (ll i=cot-1;i>=d;i--) a[hang][i]=gt++; for (ll i=hang-1;i>d;i--) a[i][d]=gt++; d++; hang--; cot--; } for (ll i=0;i<n;i++) { for (ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<endl; } return 0; }