Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
spiral traversal of a matrix
#include <bits/stdc++.h> using namespace std; int main() { //code int t; cin>>t; while(t--) { int m,n;cin>>m>>n; int vect[m][n]; for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { cin>>vect[i][j]; } } int left=0; int right=n-1; int top=0; int bottom=m-1; while(top<=bottom && left<=right) { for(int i=left;i<=right;i++) cout<<vect[top][i]<<" "; top++; for(int i=top;i<=bottom;i++) cout<<vect[i][right]<<" "; right--; if(top<=bottom) { for(int i=right;i>=left;i--) { cout<<vect[bottom][i]<<" "; } bottom--; } if(left<=right) { for(int i=bottom;i>=top;i--) { cout<<vect[i][left]<<" "; } left++; } } cout<<endl; } return 0; }
run
|
edit
|
history
|
help
0
Count edges in a graph
CutRod
რიცხვები დაფაზა~ფინალური
POI
СП КИ ЭТАП 2
DP on Trees: Type B (In/out Dp)
Simulare 2022
C++ virtual dispose
Logical AND versus Bitwise AND
Sum of digits of number