Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Matrix spiral print
//Title of this code #include <iostream> using namespace std; template<int rows, int cols> void spirallyPrint(const int t[rows][cols]) { int hStart = 0; // horizontal start int hEnd = cols - 1; // horizontal end int vStart = 0; // vertical start int vEnd = rows - 1; // vertical end while (hStart <= hEnd && vStart <= vEnd) { // horizontal left to right for (int i = hStart; i <= hEnd; ++i) cout << t[vStart][i] << " "; ++vStart; // first row done cout << endl << hStart << " " << hEnd << " " << vStart << " " << vEnd << endl; // vertical top to bottom for (int i = vStart; i <= vEnd; ++i) cout << t[i][hEnd] << " "; --hEnd; // last column done // horizontal right to left for (int i = hEnd; i >= hStart; --i) cout << t[vEnd][i] << " "; --vEnd; // last row done // vertical bottom to top for (int i = vEnd; i >= vStart; --i) cout << t[i][hStart] << " "; ++hStart; // first column done } } int main(){ int t[3][4] = { {1, 2, 3, 4}, {3, 4, 5, 6}, {5, 6, 7, 8} }; spirallyPrint<3, 4>(t); }
run
|
edit
|
history
|
help
0
Kolokwium_2011_z7
linkage
Dar
2021, M2, Simulare;S3: 2
decode
an awesome question of basic graph traversal (786A)
SEGMENTED SIEVE
Hii
generate BinTree from sorted list
Get all anagrams from given words