diff --git a/CodeWars/src/Snail/VS_Proj/Source.cpp b/CodeWars/src/Snail/VS_Proj/Source.cpp new file mode 100644 index 0000000..ef48781 --- /dev/null +++ b/CodeWars/src/Snail/VS_Proj/Source.cpp @@ -0,0 +1,92 @@ +#include +#include +#include + +void snail( + const std::vector>& snail_map, + std::vector& result, + int topRow, + int rightColumn, + int bottomRow, + int leftColumn, + int n) +{ + + if (topRow > bottomRow) + return; + + for (int i = leftColumn; i <= rightColumn; ++i) + result.push_back(snail_map[topRow][i]); + + for (int i = topRow + 1; i <= bottomRow; ++i) + result.push_back(snail_map[i][rightColumn]); + + for (int i = rightColumn - 1; i >= leftColumn; --i) + result.push_back(snail_map[bottomRow][i]); + + for (int i = bottomRow - 1; i >= leftColumn + 1 ; --i) + result.push_back(snail_map[i][leftColumn]); + + + snail( + snail_map, + result, + topRow + 1, + rightColumn - 1, + bottomRow - 1, + leftColumn + 1, + n-1); + +} +std::vector snail(const std::vector> &snail_map) +{ + const size_t mapSize = snail_map.size(); + std::vector result; + + if (mapSize == 1) + return !snail_map[0].size() ? + result : std::vector{ snail_map[0][0] }; + + snail( + snail_map, + result, + 0, + mapSize - 1, + mapSize - 1, + 0, + mapSize); + + return result; +} +int main() +{ + + std::vector> v = {{1,2,3}, {8,9,4}, {7,6,5}}; + std::vector expected = {1,2,3,4,5,6,7,8,9}; + assert(snail(v) == expected); + + auto res = snail(v); + for (auto elem : res) + std::cout << elem << ", "; + + v = {{1,2,3,4}, {12,13,14,5}, {11,16,15,6}, {10,9,8,7}}; + expected = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; + assert(snail(v) == expected); + + v = {{1,2}, {4,3}}; + expected = {1,2,3,4}; + assert(snail(v) == expected); + + + v = {{}}; + expected = {}; + assert(snail(v) == expected); + + v = {{1}}; + expected = {1}; + assert(snail(v) == expected); + + + + return 0; +} \ No newline at end of file diff --git a/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj b/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj new file mode 100644 index 0000000..0a77b88 --- /dev/null +++ b/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1e9bef5e-1a63-4087-aa16-faf337b87595} + VSProj + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj.filters b/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj.filters new file mode 100644 index 0000000..3e7e62e --- /dev/null +++ b/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj.user b/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/CodeWars/src/Snail/VS_Proj/VS_Proj.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file