\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{emilyle1104} \pdfinfo{ /Title (the-not-yet-optimal-algorithms.pdf) /Creator (Cheatography) /Author (emilyle1104) /Subject (the not-yet optimal algorithms Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{000000} \definecolor{LightBackground}{HTML}{F7F7F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{the not-yet optimal algorithms Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{emilyle1104} via \textcolor{DarkBackground}{\uline{cheatography.com/197027/cs/41479/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}emilyle1104 \\ \uline{cheatography.com/emilyle1104} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 30th November, 2023.\\ Updated 11th April, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{void findMin (int a{[}{]}, int n)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline void findMin (int a{[}{]}, int n) \newline \{ \newline int min = a{[}0{]}; \newline for (int i = 1; i \textless{} n; i++) \newline \{ \newline if (a{[}i{]} \textless{} min) \newline \{ \newline min = a{[}i{]}; \newline \} \newline \} \newline std::cout \textless{}\textless{} "The minimun element is" \textless{}\textless{} min \textless{}\textless{} std::endl; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Arrays/findIndex}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline void findIndex(int a{[}{]}, int n, int key) \newline \{ \newline int start = -1, end = -1; \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline if(a{[}i{]} == key) \newline \{ \newline start = i; \newline break; \newline \} \newline \} \newline for (int j = n - 1; j \textgreater{}= 0; j-{}-) \newline \{ \newline if(a{[}j{]} == key) \newline \{ \newline end = j; \newline break; \newline \} \newline \} \newline if (start == -1 || end == -1) \newline \{ \newline std::cout \textless{}\textless{} -1; \newline \} \newline else \newline \{ \newline std::cout \textless{}\textless{} start \textless{}\textless{} " " \textless{}\textless{} end; \newline \} \newline \} \newline \newline int main() \newline \{ \newline int n; \newline std::cin \textgreater{}\textgreater{} n; \newline int a{[}n{]}; \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline std::cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline int key; \newline std::cin \textgreater{}\textgreater{} key; \newline findIndex(a, n, key); \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{đếm số lần xuất hiện của giá trị x}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline int countOccurrences(int a{[}{]}, int n, int x) \newline \{ \newline int count = 0; \newline for (int i = 0; i \textless{} n; ++i) \newline \{ \newline if(a{[}i{]} == x) \newline \{ \newline ++count; \newline \} \newline \} \newline return count; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{kiểm tra mảng có tăng dần không}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline bool isAscendingOrder(int a{[}{]}, int n) \newline \{ \newline for (int i = 0; i \textless{} n - 1; ++i) \newline \{ \newline if(a{[}i{]} \textgreater{} a{[}i + 1{]}) \newline \{ \newline return false; \newline \} \newline \} \newline return true; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{concatTwoArrays}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline void concatTwoArrays(int a{[}{]}, int n, int b{[}{]}, int m, int c{[}{]}) \newline \{ \newline int k = m + n; \newline int j = n; \newline for (int i = 0; i \textless{} n; ++i) \newline \{ \newline c{[}i{]} = a{[}i{]}; \newline \} \newline for (int g = 0; j \textless{} k; ++g) \newline \{ \newline c{[}j{]} = b{[}g{]}; \newline ++j; \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{xuất chuỗi theo thứ tự ngược}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline void reverseCharArray (char a{[}{]}, int n) \newline \{ \newline char tmp; \newline for (int i = 0; i \textless{} n / 2; ++i) \newline \{ \newline tmp = a{[}i{]}; \newline a{[}i{]} = a{[}n - i - 1{]}; \newline a{[}n - i - 1{]} = tmp; \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{kiểm tra chuỗi đối xứng}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline bool checkSymmetricArray(char a{[}{]}, int n) \newline \{ \newline for (int i = 0; i \textless{} n / 2; i++) \newline \{ \newline if(a{[}i{]} != a{[}n - i -1{]}) \newline \{ \newline return false; \newline \} \newline \} \newline return true; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{đếm số lần xuất hiện của kí tự c}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int \seqsplit{countOccurrencesChar(char} a{[}{]}, int n, char c) \newline \{ \newline int count = 0; \newline for (int i = 0; i \textless{} n; ++i) \newline \{ \newline if (a{[}i{]} == c) \newline \{ \newline ++count; \newline \} \newline \} \newline return count; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Hàm nhập mảng m dòng n cột}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{void set2dArray(int a{[}{]}{[}MAX{]}, int \&m, int \&n) \newline \{ \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline std::cin \textgreater{}\textgreater{} a{[}i{]}{[}j{]}; \newline \} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{h tổng các phần tử của mảng 2d}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int sumArray(int a{[}{]}{[}MAX{]}, int m, int n) \newline \{ \newline int sum = 0; \newline for (int i = 0; i \textless{} m; i++) \newline \{ \newline for (int j = 0; j \textless{} n; j++) \newline \{ \newline sum = sum + a{[}i{]}{[}j{]}; \newline \} \newline \} \newline return sum; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Hàm tính tổng đường chéo chính}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline int sumDiagonal (int a{[}{]}{[}MAX{]}, int m, int n) \newline \{ \newline int sum = 0; \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline sum = sum + a{[}i{]}{[}i{]}; \newline \} \newline return sum; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{đếm mảng có bao nhiêu số nguyên tố}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \#include \textless{}cmath\textgreater{} \newline bool checkPrime(int n) \newline \{ \newline if (n \textless{}= 1) \newline \{ \newline return false; \newline \} \newline else if (n == 2) \newline \{ \newline return true; \newline \} \newline else if (n \% 2 == 0) \newline \{ \newline return false; \newline \} \newline else if (n \textgreater{} 2) \newline \{ \newline for (int i = 3; i \textless{}= sqrt(n); i += 2) \newline \{ \newline if (n \% i == 0) \newline return false; \newline \} \newline \} \newline return true; \newline \} \newline int countNumberofPrime (int a{[}{]}, int n) \newline \{ \newline int count = 0; \newline for(int i = 0; i \textless{} n; i++) \newline \{ \newline if(checkPrime(a{[}i{]})) \newline \{ \newline ++count; \newline \} \newline \} \newline return count; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{longerSyl(word, len, syllable)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include\textless{}iostream\textgreater{} \newline \#include\textless{}string\textgreater{} \newline \newline bool isVowel (char t) \newline \{ \newline return (t =='a' || t =='e' || t =='i' || t =='o' || t =='u' || t =='y' || \newline t =='A' || t =='E' || t =='I' || t =='O' || t =='U' || t =='Y'); \newline \} \newline std::string \seqsplit{findLongestSyl(std::string} sentences)\{ \newline // sentences = "hoc mon nhap mon lap trinh rat vui" \newline // return "inh" \newline \newline int i = 0, max\_index, max\_len = 0, current\_index, current\_len = 0; \newline while (!isVowel(sentences{[}i{]})) i ++; \newline max\_index = i; \newline // Assign max to first syllabus \newline while(sentences{[}i{]} != ' ' \&\& sentences{[}i{]} != 0) \newline \{ \newline i++; \newline max\_len++; \newline \} \newline while(sentences{[}i{]} != 0) \newline \{ \newline current\_len = 0; \newline while(!isVowel(sentences{[}i{]})) i++; \newline current\_index = i; \newline while((sentences{[}i{]} != ' ' \&\& sentences{[}i{]} != 0)) \newline \{ \newline i++; \newline current\_len++; \newline \} \newline if(current\_len \textgreater{} max\_len) \newline \{ \newline max\_len = current\_len; \newline max\_index = current\_index; \newline \} \newline \} \newline // Copy to string \newline char sys{[}20{]} = \{0\}; \newline for(int j = 0; j \textless{} max\_len; j++) \newline \{ \newline sys{[}j{]} = sentences{[}j + max\_index{]}; \newline \} \newline return (std::string) sys; \newline \} \newline int main() \newline \{ \newline char sentences{[}{]} = "hooooooc mon nhap mon lap trinh rat vuaWQWVViqw"; \newline std::string output = \seqsplit{findLongestSyl(sentences);} \newline std::cout \textless{}\textless{} output; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{findext lam dai dfskdhfkjsfh}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \#include \textless{}string\textgreater{} \newline \#include \textless{}cstring\textgreater{} \newline \newline void FindExt( std::string paths{[}{]}, int nPath, std::string extName, std::string results{[}{]}, int \&nRes) \newline \{ \newline for (int i = 0; i \textless{} nPath; i++) \newline \{ \newline if(extName == paths{[}i{]}) \newline \{ \newline for (int j = 0; j \textless{} nPath; j++) \newline \{ \newline results{[}j{]} = paths{[}i{]}; \newline \} \newline nRes++; \newline \} \newline \} \newline \} \newline \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ \newline poe \newline \#include \textless{}iostream\textgreater{} \newline \#include \textless{}string\textgreater{} \newline \newline void FindExt(std::string paths{[}{]}, int nPath, std::string extName, std::string results{[}{]}, int\& nRes) \newline \{ \newline for (int i = 0; i \textless{} nPath; i++) \newline \{ \newline if (paths{[}i{]}.find(extName) != std::string::npos) \newline \{ \newline results{[}nRes{]} = paths{[}i{]}; \newline nRes++; \newline \} \newline \} \newline \} \newline \newline int main() \newline \{ \newline std::string paths{[}{]} = \{ "D:/Others/us/b.pdf", "C:/Users/c.txt", "C:/Users/adm/a.txt", "E:/temp/d.exe" \}; \newline int nPath = 4; \newline std::string results{[}4{]}; \newline std::string extName = "txt"; \newline int nRes = 0; \newline FindExt(paths, nPath, extName, results, nRes); \newline for (int i = 0; i \textless{} nRes; i++) \newline \{ \newline std::cout \textless{}\textless{} results{[}i{]} \textless{}\textless{} " "; \newline \} \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{void RemovePhone}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline struct Phone \newline \{ \newline int ID; \newline int version; \newline int year; \newline \}; \newline \newline void RemovePhone(Phone listPhone{[}{]}, int \&nPhone, int curYear) \newline \{ \newline int elementsDeleted = 0; \newline for (int i = 0; i \textless{} nPhone; i++) \newline \{ \newline if (curYear - listPhone{[}i{]}.year \textgreater{} 4) \newline \{ \newline for(int j = i; j \textless{} nPhone; j++) \newline \{ \newline listPhone{[}j{]} = listPhone{[}j + 1{]}; \newline \} \newline i-{}-; \newline nPhone-{}-; \newline \} \newline \} \newline \} \newline \newline int main() \newline \{ \newline \newline \newline Phone listPhone{[}100{]} = \{\{10, 9, 2019\}, \{20, 10, 2020\}, \{21, 11, 2021\}, \{22, 12, 2022\}, \{9, 8, 2018\}\}; \newline int nPhone = 5; \newline int curYear = 2024; \newline RemovePhone(listPhone, nPhone, curYear); \newline // In ra ID cua cac dien thoai con lai \newline for (int i = 0; i \textless{} nPhone; i++) \newline std::cout \textless{}\textless{} listPhone{[}i{]}.ID \textless{}\textless{} " "; \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{vd cua convert char array to string}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \#include \textless{}string\textgreater{} \newline int main() \newline \{ \newline char cstr{[}{]} = "clc03"; \newline std::string s(cstr); \newline std::cout \textless{}\textless{} s; \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Hàm xoá các phần tử có giá trị x}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline void deleteItems (int a{[}{]}, int \&n, int x) \newline \{ \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline if (a{[}i{]} == x) \newline \{ \newline for (int j = i; j \textless{} n; j++) \newline \{ \newline a{[}j{]} = a{[}j + 1{]}; \newline \} \newline i-{}-; \newline n-{}-; \newline \} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{void deleteItemsFromIndex}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline void deleteItemsFromIndex(int a{[}{]}, int \&n, int index, int no\_items) \newline \{ \newline for(int i = index ; i \textless{} index + no\_items; ++i) \newline \{ \newline if (i + no\_items \textless{} n) \newline \{ \newline a{[}i{]} = a{[}i + no\_items{]}; \newline \} \newline else \newline \{ \newline break; \newline \} \newline \} \newline n = n - std::min(no\_items, std::max(n - index, 0)); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{mảng đánh dấu}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{//hãy đếm xem có bao nhiêu giá trị khác nhau trong mảng; \newline int main() \{ \newline int count{[}1000001{]} = \{0\}; \newline int n; \newline cin \textgreater{}\textgreater{} n; \newline int a{[}n{]}; \newline for(int i = 0; i \textless{} n; i++) \newline \{ \newline cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline count{[}a{[}i{]}{]} = 1; \newline \} \newline int ans = 0; \newline for (int i = 0; i \textless{}= 1000000; i++) \newline \{ \newline if(count{[}i{]} == 1) ++ans; \newline \} \newline cout \textless{}\textless{} ans; \newline return 0; \newline \} \newline // hãy liệt kê các giá trị xuất hiện trong mảng theo thứ tự từ nhỏ đến lớn kèm theo tần suất của nó \newline int cnt{[}1000001{]}; \newline int main() \newline \{ \newline int n; \newline cin \textgreater{}\textgreater{} n; \newline int a{[}n{]}; \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline cnt{[}a{[}i{]}{]}++; \newline \} \newline for (int i = 0; i \textless{}= 1000000; i++) \newline \{ \newline if(cnt{[}i{]} != 0) cout \textless{}\textless{} i \textless{}\textless{} " " \textless{}\textless{} cnt{[}i{]} \textless{}\textless{} endl; \newline \} \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{mò 1d arra}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{//liệt kê \newline for(int i = 0; i \textless{} n; i++) \newline \{ \newline bool check = true; \newline for(int j = 0; j \textless{}= n - 1; j++) \newline \{ \newline if(a{[}j{]} == a{[}i{]}) \newline \{ \newline check = false; \newline break; \newline \} \newline \} \newline if(check) cout \textless{}\textless{} a{[}i{]} \textless{}\textless{} " "; \newline \} \newline // đếm tần suất \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline bool check = true; \newline for (int j = 0; j \textless{}= i - 1; j++) \newline \{ \newline if(a{[}j{]} == a{[}i{]}) \newline \{ \newline check = false; \newline break; \newline \} \newline \} \newline if (check) \newline \{ \newline int frequency = 1; \newline for (int j = i + 1; j \textless{} n; j++) \newline \{ \newline if(a{[}i{]} == a{[}j{]}) ++frequency; \newline \} \newline cout \textless{}\textless{} a{[}i{]} \textless{}\textless{} " " \textless{}\textless{} frequency \textless{}\textless{} endl; \newline \} \newline \} \newline ool checkdx(int a{[}{]}, int n) \newline \{ \newline for(int i = 0; i \textless{} n / 2; i++) \newline \{ \newline if(a{[}i{]} != a{[}n - i - 1{]}) return false; \newline \} \newline return true; \newline \} \newline //lật mảng: duyệt các element đối xứng nhau và swap nó là được \newline void latmang(int a{[}{]}, int n) \newline \{ \newline for(int i = 0; i \textless{} n /2; i++) \newline \{ \newline swap(a{[}i{]}, a{[}n - 1 - i{]}); \newline \} \newline \} \newline // xóa phần tử tại k \newline void xoa(int a{[}{]}, int \&n, int k) \newline \{ \newline for(int i = k; i \textless{} n - 1; i++) \newline \{ \newline a{[}i{]} = a{[}i + 1{]}; \newline \} \newline -{}-n; \newline \} \newline // -{}-n để giảm kích thước của mảng \newline //chèn phần tử \newline void chen(int a{[}{]}, int \&n, int k, int x) \newline \{ \newline for(int i = n; i \textgreater{} k; i-{}-) //không phải n - 1 vì \newline \{ \newline a{[}i{]} = a{[}i - 1{]}; \newline \} \newline a{[}k{]} = x; \newline ++n; \newline //++n dê tăng kích thước của mảng \newline \} \newline // fibo \newline bool check(long long n) \newline \{ \newline long long f{[}100{]}; \newline f{[}0{]} = 0; \newline f{[}1{]} = 1; \newline for (int i = 2; i \textless{}= 92; i++) \newline \{ \newline \newline f{[}i{]} = f{[}i - 1{]} + f{[}i - 2{]}; \newline \} \newline for (int i = 0; i \textless{}= 92; i++) \newline \{ \newline if(f{[}i{]} == n) return true; \newline \} \newline return false; \newline \} \newline // trộn 2 mảng tăng dần \newline int a{[}{]} = \{1, 2, 5, 6\}; \newline int b{[}{]} = \{4, 8, 9, 10, 11, 29\}; \newline int n = 4 //số elements của a; \newline int m = 6 //só elements của b; \newline int i = 0, j = 0; \newline while(i \textless{} n \&\& j \textless{} m) \newline \{ \newline if(a{[}i{]} \textless{}= b{[}j{]}) \newline \{ \newline cout \textless{}\textless{} a{[}i{]} \textless{}\textless{} " "; \newline i++; \newline \} \newline else \newline \{ \newline cout \textless{}\textless{} b{[}j{]} \textless{}\textless{} " "; \newline j++; \newline \} \newline \} \newline while (i \textless{} n) \newline \{ \newline cout \textless{}\textless{} a{[}i{]} \textless{}\textless{} " "; \newline i++; \newline \} \newline while (j \textless{} m) \newline \{ \newline cout \textless{}\textless{} b{[}j{]} \textless{}\textless{} " "; \newline j++; \newline \} \newline //tìm phần tử đầu tiên lớn hơn nó nằm ở bên phải, đối với phần tử không có phần tử lớn hơn bên phải thì in ra -1, ví dụ mảng A{[}{]} là \{3, 8, 9, 1, 4, 2, 5\} thì kết quả sẽ là 8, 9, -1, 4, 5, 5, -1. \newline int main() \newline \{ \newline int n; \newline cin \textgreater{}\textgreater{} n; \newline int a{[}n{]}; \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline bool check = true; \newline for(int j = i + 1; j \textless{} n; j++) \newline \{ \newline if(a{[}i{]} \textless{} a{[}j{]}) \newline \{ \newline check = false; \newline cout \textless{}\textless{} a{[}j{]} \textless{}\textless{} " "; \newline break; \newline \} \newline \} \newline if(check) \newline \{ \newline cout \textless{}\textless{} -1 \textless{}\textless{} " "; \newline \} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{fibo matrix but it's ai created}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline using namespace std; \newline \newline void print\_spiral\_fibo(int n) \{ \newline int fib{[}n{\emph{n{]} = \{0, 1\}; \newline for (int i = 2; i \textless{} n}}n; i++) \{ \newline fib{[}i{]} = fib{[}i-1{]} + fib{[}i-2{]}; \newline \} \newline \newline int start\_row = 0, start\_col = 0, end\_row = n-1, end\_col = n-1; \newline while (start\_row \textless{}= end\_row \&\& start\_col \textless{}= end\_col) \{ \newline // Print the first row from the remaining rows \newline for (int i = start\_col; i \textless{}= end\_col; i++) \{ \newline cout \textless{}\textless{} fib{[}start\_row {\emph{ n + i{]} \textless{}\textless{} " "; \newline \} \newline start\_row++; \newline \newline // Print the last column from the remaining columns \newline for (int i = start\_row; i \textless{}= end\_row; i++) \{ \newline cout \textless{}\textless{} fib{[}i }} n + end\_col{]} \textless{}\textless{} " "; \newline \} \newline end\_col-{}-; \newline \newline // Print the last row from the remaining rows \newline if (start\_row \textless{}= end\_row) \{ \newline for (int i = end\_col; i \textgreater{}= start\_col; i-{}-) \{ \newline cout \textless{}\textless{} fib{[}end\_row {\emph{ n + i{]} \textless{}\textless{} " "; \newline \} \newline end\_row-{}-; \newline \} \newline \newline // Print the first column from the remaining columns \newline if (start\_col \textless{}= end\_col) \{ \newline for (int i = end\_row; i \textgreater{}= start\_row; i-{}-) \{ \newline cout \textless{}\textless{} fib{[}i }} n + start\_col{]} \textless{}\textless{} " "; \newline \} \newline start\_col++; \newline \} \newline \} \newline \} \newline \newline int main() \{ \newline int n; \newline cout \textless{}\textless{} "Enter the size of the spiral matrix: "; \newline cin \textgreater{}\textgreater{} n; \newline print\_spiral\_fibo(n); \newline return 0; \newline \} \newline This function first generates an array of Fibonacci numbers up to ` \newline \newline Is this conversation helpful so far? \newline \newline \newline \newline give me some test cases \newline \newline Edit \newline \newline Sources: geeksforgeeks.org (1) programiz.com (2) geeksforgeeks.org (3) javatpoint.com (4) \newline \newline Sure, here are some test cases for the spiral matrix Fibonacci C++ program: \newline \newline Test Case n Output \newline 1 3 0 1 1 2 3 5 \newline 2 4 0 1 1 2 3 5 8 13 \newline 3 5 0 1 1 2 3 5 8 13 21 34 \newline 4 6 0 1 1 2 3 5 8 13 21 34 55 89 \newline 5 7 0 1 1 2 3 5 8 13 21 34 55 89 144 233 \newline And here is the C++ code to print a spiral matrix whose elements are Fibonacci numbers: \newline \newline cpp \newline Edit \newline Full Screen \newline Copy code \newline \#include \textless{}iostream\textgreater{} \newline using namespace std; \newline \newline void printSpiral(int n) \{ \newline int fib{[}n{\emph{n{]} = \{0, 1\}; \newline for (int i = 2; i \textless{} n}}n; i++) \{ \newline fib{[}i{]} = fib{[}i-1{]} + fib{[}i-2{]}; \newline \} \newline \newline int start\_row = 0, start\_col = 0, end\_row = n-1, end\_col = n-1; \newline while (start\_row \textless{}= end\_row \&\& start\_col \textless{}= end\_col) \{ \newline // Print the first row from the remaining rows \newline for (int i = start\_col; i \textless{}= end\_col; i++) \{ \newline cout \textless{}\textless{} fib{[}start\_row {\emph{ n + i{]} \textless{}\textless{} " "; \newline \} \newline start\_row++; \newline \newline // Print the last column from the remaining columns \newline for (int i = start\_row; i \textless{}= end\_row; i++) \{ \newline cout \textless{}\textless{} fib{[}i }} n + end\_col{]} \textless{}\textless{} " "; \newline \} \newline end\_col-{}-; \newline \newline // Print the last row from the remaining rows \newline if (start\_row \textless{}= end\_row) \{ \newline for (int i} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{spiral matrix (ngược chiều dượng}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{// C++ Program to print a matrix spirally \newline \newline \#include \textless{}bits/stdc++.h\textgreater{} \newline using namespace std; \newline \#define R 4 \newline \#define C 4 \newline \newline void spiralPrint(int m, int n, int a{[}R{]}{[}C{]}) \newline \{ \newline int i, k = 0, l = 0; \newline \newline /{\emph{ k - starting row index \newline m - ending row index \newline l - starting column index \newline n - ending column index \newline i - iterator \newline }}/ \newline \newline while (k \textless{} m \&\& l \textless{} n) \{ \newline /{\emph{ Print the first row from \newline the remaining rows }}/ \newline for (i = l; i \textless{} n; ++i) \{ \newline cout \textless{}\textless{} a{[}k{]}{[}i{]} \textless{}\textless{} " "; \newline \} \newline k++; \newline \newline /{\emph{ Print the last column \newline from the remaining columns }}/ \newline for (i = k; i \textless{} m; ++i) \{ \newline cout \textless{}\textless{} a{[}i{]}{[}n - 1{]} \textless{}\textless{} " "; \newline \} \newline n-{}-; \newline \newline /{\emph{ Print the last row from \newline the remaining rows }}/ \newline if (k \textless{} m) \{ \newline for (i = n - 1; i \textgreater{}= l; -{}-i) \{ \newline cout \textless{}\textless{} a{[}m - 1{]}{[}i{]} \textless{}\textless{} " "; \newline \} \newline m-{}-; \newline \} \newline \newline /{\emph{ Print the first column from \newline the remaining columns }}/ \newline if (l \textless{} n) \{ \newline for (i = m - 1; i \textgreater{}= k; -{}-i) \{ \newline cout \textless{}\textless{} a{[}i{]}{[}l{]} \textless{}\textless{} " "; \newline \} \newline l++; \newline \} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{tượng}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int countSquares(int row, int column) \newline \{ \newline \newline // Count top left squares \newline int topLeft = min(row, column) - 1; \newline \newline // Count bottom right squares \newline int bottomRight = 8 - max(row, column); \newline \newline // Count top right squares \newline int topRight = min(row, 9 - column) - 1; \newline \newline // Count bottom left squares \newline int bottomLeft = 8 - max(row, 9 - column); \newline \newline // Return total count \newline return (topLeft + topRight + bottomRight + bottomLeft); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{quân mã}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int findPossibleMoves(int mat{[}n{]}{[}m{]}, int p, int q) \newline \{ \newline // All possible moves of a knight \newline int X{[}8{]} = \{ 2, 1, -1, -2, -2, -1, 1, 2 \}; \newline int Y{[}8{]} = \{ 1, 2, 2, 1, -1, -2, -2, -1 \}; \newline \newline int count = 0; \newline \newline // Check if each possible move is valid or not \newline for (int i = 0; i \textless{} 8; i++) \{ \newline \newline // Position of knight after move \newline int x = p + X{[}i{]}; \newline int y = q + Y{[}i{]}; \newline \newline // count valid moves \newline if (x \textgreater{}= 0 \&\& y \textgreater{}= 0 \&\& x \textless{} n \&\& y \textless{} m \newline \&\& mat{[}x{]}{[}y{]} == 0) \newline count++; \newline \} \newline \newline // Return number of possible moves \newline return count; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{lớn nhất và lớn thứ 2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int main() \{ \newline long long m; \newline cin \textgreater{}\textgreater{} m; \newline long long a{[}m{]}; \newline for(long long i = 0; i \textless{} m; i++) \newline \{ \newline cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline long long max1 = 0; \newline long long max2 = 0; \newline int index1 = 0; \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline if(a{[}i{]} \textgreater{} max1) \newline \{ \newline max1 = a{[}i{]}; \newline index1 = i; \newline \} \newline \} \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline if(a{[}i{]} \textgreater{} max2 \&\& i != index1) \newline \{ \newline max2 = a{[}i{]}; \newline \} \newline \} \newline cout \textless{}\textless{} max1 \textless{}\textless{} " " \textless{}\textless{} max2; \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{lớn nhất và lớn thứ 2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int main() \{ \newline long long m; \newline cin \textgreater{}\textgreater{} m; \newline long long a{[}m{]}; \newline for(long long i = 0; i \textless{} m; i++) \newline \{ \newline cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline long long max1 = 0; \newline long long max2 = 0; \newline int index1 = 0; \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline if(a{[}i{]} \textgreater{} max1) \newline \{ \newline max1 = a{[}i{]}; \newline index1 = i; \newline \} \newline \} \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline if(a{[}i{]} \textgreater{} max2 \&\& i != index1) \newline \{ \newline max2 = a{[}i{]}; \newline \} \newline \} \newline cout \textless{}\textless{} max1 \textless{}\textless{} " " \textless{}\textless{} max2; \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{lớn nhất và lớn thứ 2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{int main() \{ \newline long long m; \newline cin \textgreater{}\textgreater{} m; \newline long long a{[}m{]}; \newline for(long long i = 0; i \textless{} m; i++) \newline \{ \newline cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline long long max1 = 0; \newline long long max2 = 0; \newline int index1 = 0; \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline if(a{[}i{]} \textgreater{} max1) \newline \{ \newline max1 = a{[}i{]}; \newline index1 = i; \newline \} \newline \} \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline if(a{[}i{]} \textgreater{} max2 \&\& i != index1) \newline \{ \newline max2 = a{[}i{]}; \newline \} \newline \} \newline cout \textless{}\textless{} max1 \textless{}\textless{} " " \textless{}\textless{} max2; \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{gcd in arrays}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}cmath\textgreater{} \newline \#include \textless{}cstdio\textgreater{} \newline \#include \textless{}vector\textgreater{} \newline \#include \textless{}iostream\textgreater{} \newline \#include \textless{}algorithm\textgreater{} \newline using namespace std; \newline long long gcd(long long a, long long b) \newline \{ \newline while (b!= 0) \newline \{ \newline long long r = a \% b; \newline a = b; \newline b = r; \newline \} \newline return a; \newline \} \newline \newline int main() \{ \newline long long n; \newline cin \textgreater{}\textgreater{} n; \newline long long a{[}n{]}; \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline long long gcd1 = gcd(a{[}0{]}, a{[}1{]}); \newline for(int i = 0; i \textless{} n; i++) \newline \{ \newline gcd1 = gcd(gcd1, a{[}i{]}); \newline \} \newline cout \textless{}\textless{} gcd1; \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{fibo}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{bool isFibo(long long n) \newline \{ \newline long long f{[}93{]}; \newline if (n == 1 || n == 0) return true; \newline f{[}0{]} = 0; \newline f{[}1{]} = 1; \newline for (int i = 2; i \textless{} 93; i++) \newline \{ \newline f{[}i{]} = f{[}i - 1{]} + f{[}i - 2{]}; \newline \} \newline for (int i = 0; i \textless{} 93; i++) \newline \{ \newline if(f{[}i{]} == n) \newline \{ \newline return true; \newline \} \newline \} \newline return false; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{week5}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \newline using namespace std; \newline \newline \#define MAX 100 \newline \newline void set2DArray(int a{[}{]}{[}MAX{]}, int \&m, int \&n) \{ \newline cin \textgreater{}\textgreater{} m \textgreater{}\textgreater{} n; \newline \newline for (int i = 0; i \textless{} m; i++) \newline for (int j = 0; j \textless{} n; j++) \newline cin \textgreater{}\textgreater{} a{[}i{]}{[}j{]}; \newline \} \newline void print2DArr(int a{[}{]}{[}MAX{]}, int m, int n) \{ \newline for (int i = 0; i \textless{} m; i++) \{ \newline for (int j = 0; j \textless{} n; j++) \newline cout \textless{}\textless{} a{[}i{]}{[}j{]} \textless{}\textless{} ' '; \newline cout \textless{}\textless{} endl; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline int sum2DArray(int a{[}{]}{[}MAX{]}, int m, int n) \{ \newline int sum = 0; \newline for (int i = 0; i \textless{} m; i++) \newline for (int j = 0; j \textless{} n; j++) \newline sum += a{[}i{]}{[}j{]}; \newline return sum; \newline \} \newline \newline int sumDiagonal(int a{[}{]}{[}MAX{]}, int m, int n) \{ \newline int sum = 0; \newline // for (int i = 0; i \textless{} m; i++) \{ \newline // for(int j = 0; j \textless{} n; j++) \{ \newline // if(i == j) \newline // sum += a{[}i{]}{[}j{]}; \newline // \} \newline // \} \newline \newline for (int i = 0; i \textless{} m; i++) \newline sum += a{[}i{]}{[}i{]}; \newline \newline return sum; \newline \} \newline \newline int findMin(int a{[}{]}{[}MAX{]}, int m, int n) \{ \newline int min = a{[}0{]}{[}0{]}; \newline for(int i = 0; i \textless{} m; i++) \{ \newline for(int j = 0; j \textless{} n; j++) \{ \newline if (a{[}i{]}{[}j{]} \textless{} min) \newline min = a{[}i{]}{[}j{]}; \newline \} \newline \} \newline return min; \newline \} \newline \newline bool checkPrime(int n) \newline \{ \newline if (n \textless{} 2) \newline return false; \newline if (n == 2) \newline return true; \newline if (n \% 2 == 0) \newline return false; \newline for (int i = 3; i \textless{}= n / 2; i = i + 2) \newline \{ \newline if (n \% i == 0) \newline return false; \newline \} \newline \newline return true; \newline \} \newline \newline int countNumberOfPrime(int a{[}{]}{[}MAX{]}, int m, int n) \newline \{ \newline int count = 0; \newline for (int i = 0; i \textless{} m; ++i) \newline \{ \newline for (int j = 0; j \textless{} n; ++j) \newline \{ \newline count += checkPrime(a{[}i{]}{[}j{]}); \newline \} \newline \} \newline \newline return count; \newline \} \newline \newline bool isUnappear(int a{[}{]}, int n, int x)\{ \newline for(int i = 0; i \textless{} n; i++)\{ \newline if(a{[}i{]} == x) \newline return false; \newline \} \newline return true; \newline \} \newline \newline int \seqsplit{countNumberOfUniquePrime(int} a{[}{]}{[}MAX{]}, int m, int n)\{ \newline int temp{[}MAX*MAX{]}; \newline int l = 0; \newline for(int i = 0; i \textless{} m; i++)\{ \newline for(int j = 0; j \textless{} n; j++)\{ \newline if(checkPrime(a{[}i{]}{[}j{]}) \&\& isUnappear(temp, l, a{[}i{]}{[}j{]}))\{ \newline temp{[}l{]} = a{[}i{]}{[}j{]}; \newline l++; \newline \} \newline \} \newline \} \newline return l; \newline \} \newline \newline int countOccurrences(int a{[}{]}{[}MAX{]}, int m, int n, int x) \{ \newline int count = 0; \newline for( int i = 0; i \textless{} m; i++) \newline for (int j = 0; j \textless{} n; j++) \newline if (a{[}i{]}{[}j{]} == x) \newline count++; \newline \newline return count; \newline \newline \newline \} \newline \newline void delete\_row(int a{[}{]}{[}MAX{]}, int \&m, int n, int idx) \newline \{ \newline for (int i = idx; i \textless{} m - 1; i++) \newline \{ \newline for (int j = 0; j \textless{} n; j++) \newline \{ \newline a{[}i{]}{[}j{]} = a{[}i + 1{]}{[}j{]}; \newline \} \newline \} \newline m-{}-; \newline \} \newline \newline void delete\_col(int a{[}{]}{[}MAX{]}, int m, int \&n, int idx) \newline \{ \newline for (int i = 0; i \textless{} m; i++) \newline \{ \newline for (int j = idx; j \textless{} n - 1; j++) \newline \{ \newline a{[}i{]}{[}j{]} = a{[}i{]}{[}j + 1{]}; \newline \} \newline \} \newline \newline // for (int j = idx; j \textless{} n - 1; j++) \newline // for (int i = 0; i \textless{} m; i++) \newline // a{[}i{]}{[}j{]} = a{[}i{]}{[}j + 1{]}; \newline \newline n-{}-; \newline \} \newline \newline void deleteItem(int a{[}{]}{[}MAX{]}, int \&m, int \&n, int x)\{ \newline for(int i = 0; i \textless{} m; i++)\{ \newline for(int j = 0; j \textless{} m; j++)\{ \newline if(a{[}i{]}{[}j{]} == x)\{ \newline delete\_row(a, m, n, i); \newline delete\_col(a, m, n, j); \newline j-{}-; \newline \} \newline \} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{struct sinhvien}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \#include \textless{}cstring\textgreater{} \newline \#include \textless{}iomanip\textgreater{} \newline \#pragma pack(1) \newline \newline struct SINHVIEN \newline \{ \newline char MSSV{[}9{]}; \newline char Ho\_va\_ten\_lot{[}31{]}; \newline char Ten{[}9{]}; \newline float mon1 = 0; \newline float mon2 = 0; \newline float mon3 = 0; \newline \}; \newline \newline void print(SINHVIEN sv{[}{]}, int n) \newline \{ \newline std::cout \textless{}\textless{} "MSSV" \textless{}\textless{} std::setw(10) \textless{}\textless{} "HO" \textless{}\textless{} std::setw(10) \textless{}\textless{} "Ten" \textless{}\textless{} std::setw(10) \textless{}\textless{} "D1" \textless{}\textless{} std::setw(10) \textless{}\textless{} "D2" \textless{}\textless{} std::setw(10) \textless{}\textless{} "D3\textbackslash{}n"; \newline for(int i = 0; i \textless{} n; i++) \newline std::cout \textless{}\textless{} sv{[}i{]}.MSSV \textless{}\textless{} std::setw(10) \textless{}\textless{} sv{[}i{]}.Ho\_va\_ten\_lot \textless{}\textless{} std::setw(10) \textless{}\textless{} sv{[}i{]}.Ten \textless{}\textless{} std::setw(10) \textless{}\textless{} sv{[}i{]}.mon1 \textless{}\textless{} std::setw(10) \textless{}\textless{} sv{[}i{]}.mon2 \textless{}\textless{} std::setw(10) \textless{}\textless{} sv{[}i{]}.mon3 \textless{}\textless{} "\textbackslash{}n"; \newline \} \newline \newline void sortByName(SINHVIEN sv{[}{]}, int n) \newline \{ \newline for(int i = 0; i \textless{} n; i++) \{ \newline for(int j = n - 1; j \textgreater{} i; j-{}-) \{ \newline if(strcmp(sv{[}i{]}.Ten, sv{[}j{]}.Ten) \textgreater{} 0) \newline std::swap(sv{[}i{]}, sv{[}j{]}); \newline \} \newline \} \newline \} \newline \newline int main() \newline \{ \newline SINHVIEN sv{[}{]}=\{\{"23127489", "Nguyen Ngoc Minh", "Thu", 5.0, 9.0, 6.5\}, \{"23127237", "Le Truong Bao", "Ngoc", 7.0, 4.5, 8.7\}, \{"23127525", "Tran Ngoc", "Dieu", 9.7, 1.2, 5.6\}\}; \newline int n = \seqsplit{sizeof(sv)/sizeof(SINHVIEN);} \newline std::cout \textless{}\textless{} "Danh sách ban đầu: \textbackslash{}n"; \newline print(sv, n); \newline sortByName(sv, n); \newline std::cout \textless{}\textless{} "Danh sách sau khi sắp xếp theo tên: \textbackslash{}n"; \newline print(sv, n); \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{tìm min của mảng 2d}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline int findMin(int a{[}{]}{[}MAX{]}, int m, int n) \newline \{ \newline int min = a{[}0{]}{[}0{]}; \newline for (int i = 0; i \textless{} m; i++) \newline \{ \newline for (int j = 0; j \textless{} n; j++) \newline \{ \newline if(a{[}i{]}{[}j{]} \textless{} min) \newline min = a{[}i{]}{[}j{]}; \newline \} \newline \} \newline return min; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{deleteItems}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{void deleteItems(int a{[}{]}{[}MAX{]}, int\& m, int\& n, int x) \newline \{ \newline int elementsDeleted = 0; // Variable to keep track of the number of elements deleted \newline \newline for (int i = 0; i \textless{} m; i++) \newline \{ \newline for (int j = 0; j \textless{} n; j++) \newline \{ \newline if (a{[}i{]}{[}j{]} == x) \newline \{ \newline // Shift elements to the left starting from the next position \newline for (int k = j; k \textless{} n - 1; k++) \newline \{ \newline a{[}i{]}{[}k{]} = a{[}i{]}{[}k + 1{]}; \newline \} \newline elementsDeleted++; \newline // Decrement the number of columns \newline n-{}-; \newline // Decrement j to recheck the new element at the current position \newline j-{}-; \newline \} \newline \} \newline \} \newline \newline // Update the number of rows after deletion \newline m -= elementsDeleted; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{final lab}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \#include \textless{}string\textgreater{} \newline \#include \textless{}fstream\textgreater{} \newline /{\emph{ The member function cin.getline() works with C strings (i.e. arrays of char) \newline whereas the free function std::getline() works with C++ strings (i.e. std::string.) \newline You should not be using C strings at all when learning C++, which means \newline you should not be using cin.getline().}}/ \newline using namespace std; \newline \newline void FindExt(std::string paths{[}{]}, int nPath, std::string extName, std::string results{[}{]}, int \&nRes) \newline \{ \newline nRes = 0; \newline for(int i = 0; i \textless{} nPath; i++) \newline \{ \newline string tmp = paths{[}i{]}.substr(paths{[}i{]}.find('.') + 1); \newline if(tmp == extName) \newline \{ \newline ++nRes; \newline for(int j = 0; j \textless{} nRes; j++) \newline \{ \newline results{[}j{]} = paths{[}i{]}; \newline \} \newline \} \newline \} \newline \} \newline void Find(string paths{[}{]}, int nPath, string curDir, string results{[}{]}, int \&nRes) \newline \{ \newline \newline \} \newline int main() \newline \{ \newline string paths{[}{]} = \{"D:/Others/us/b.pdf", "C:/Users/c.txt", "C:/Users/adm/a.txt", "E:/temp/d.exe"\}; \newline string extName = "txt"; \newline string results{[}1000{]}; \newline int nRes; \newline FindExt(paths, 4, extName, results, nRes); \newline for(int i = 0; i \textless{} nRes; i++) \newline \{ \newline cout \textless{}\textless{} results{[}i{]} \textless{}\textless{} " "; \newline \} \newline cout \textless{}\textless{} endl; \newline cout \textless{}\textless{} nRes; \newline return 0; \newline \} \newline \#include \textless{}iostream\textgreater{} \newline using namespace std; \newline void doMin(int a{[}{]}{[}3{]}, int m, int n) \newline \{ \newline int res{[}100{]}{[}100{]} = \{0\}; \newline \newline int toaDoX{[}8{]} = \{-1, -1, -1, 0, 0, 1, 1, 1\}; \newline int toaDoY{[}8{]} = \{-1, 0, 1, -1, 1, -1, 0, 1\}; \newline \newline for(int i = 0; i \textless{} m; ++i) \newline \{ \newline for(int j = 0; j \textless{} n; ++j) \newline \{ \newline if(a{[}i{]}{[}j{]} == 1) \newline \{ \newline for(int k = 0; k \textless{} 8; ++k) \newline \{ \newline int newX = i + toaDoX{[}k{]}; \newline int newY = j + toaDoY{[}k{]}; \newline if(newX \textgreater{}= 0 \&\& newY \textgreater{}= 0 \&\& newX \textless{} m \&\& newY \textless{} n) \newline \{ \newline ++res{[}newX{]}{[}newY{]}; \newline \} \newline \} \newline \} \newline \} \newline \} \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline a{[}i{]}{[}j{]} = res{[}i{]}{[}j{]}; \newline \} \newline \} \newline \} \newline int main() \newline \{ \newline int a{[}3{]}{[}3{]} = \{ \newline 1, 0, 0, \newline 0, 1, 0, \newline 0, 0, 0\}; \newline int m = 3; \newline int n = 3; \newline doMin(a, m, n); \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline cout \textless{}\textless{} a{[}i{]}{[}j{]} \textless{}\textless{} " "; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline return 0; \newline \} \newline \#include \textless{}iostream\textgreater{} \newline \#include \textless{}fstream\textgreater{} \newline using namespace std; \newline void ReadMap(int map{[}{]}{[}100{]}, int \&m, int \&n) \newline \{ \newline ifstream fin; \newline fin.open("map.txt"); \newline if(!fin.is\_open()) \newline \{ \newline cout \textless{}\textless{} "failed to open file!"; \newline return; \newline \} \newline fin \textgreater{}\textgreater{} m \textgreater{}\textgreater{} n; \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline fin \textgreater{}\textgreater{} map{[}i{]}{[}j{]}; \newline \} \newline \} \newline fin.close(); \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline cout \textless{}\textless{} map{[}i{]}{[}j{]} \textless{}\textless{} " "; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline \} \newline \newline int main() \newline \{ \newline int map{[}100{]}{[}100{]}; \newline int m, n; \newline ReadMap(map, m, n); \newline return 0; \newline \} \newline //các hàm \newline c\_str: string to char \newline char array to string \newline // Demonstrates conversion \newline // from character array to string \newline \newline \#include \textless{}bits/stdc++.h\textgreater{} \newline using namespace std; \newline \newline // converts character array \newline // to string and returns it \newline string convertToString(char{\emph{ a, int size) \newline \{ \newline int i; \newline string s = ""; \newline for (i = 0; i \textless{} size; i++) \{ \newline s = s + a{[}i{]}; \newline \} \newline return s; \newline \} \newline \newline // Driver code \newline int main() \newline \{ \newline char a{[}{]} = \{ 'C', 'O', 'D', 'E' \}; \newline char b{[}{]} = "geeksforgeeks"; \newline \newline int a\_size = sizeof(a) / sizeof(char); \newline int b\_size = sizeof(b) / sizeof(char); \newline \newline string s\_a = convertToString(a, a\_size); \newline string s\_b = convertToString(b, b\_size); \newline \newline cout \textless{}\textless{} s\_a \textless{}\textless{} endl; \newline cout \textless{}\textless{} s\_b \textless{}\textless{} endl; \newline \newline return 0; \newline \} \newline \newline \newline // C++ implementation of above approach \newline \#include \textless{}bits/stdc++.h\textgreater{} \newline using namespace std; \newline \newline \#define N 4 \newline \newline // Function to rotate the matrix 90 degree clockwise \newline void rotate90Clockwise(int a{[}N{]}{[}N{]}) \newline \{ \newline \newline // Traverse each cycle \newline for (int i = 0; i \textless{} N / 2; i++) \{ \newline for (int j = i; j \textless{} N - i - 1; j++) \{ \newline \newline // Swap elements of each cycle \newline // in clockwise direction \newline int temp = a{[}i{]}{[}j{]}; \newline a{[}i{]}{[}j{]} = a{[}N - 1 - j{]}{[}i{]}; \newline a{[}N - 1 - j{]}{[}i{]} = a{[}N - 1 - i{]}{[}N - 1 - j{]}; \newline a{[}N - 1 - i{]}{[}N - 1 - j{]} = a{[}j{]}{[}N - 1 - i{]}; \newline a{[}j{]}{[}N - 1 - i{]} = temp; \newline \} \newline \} \newline \} \newline \newline // Function for print matrix \newline void printMatrix(int arr{[}N{]}{[}N{]}) \newline \{ \newline for (int i = 0; i \textless{} N; i++) \{ \newline for (int j = 0; j \textless{} N; j++) \newline cout \textless{}\textless{} arr{[}i{]}{[}j{]} \textless{}\textless{} " "; \newline cout \textless{}\textless{} '\textbackslash{}n'; \newline \} \newline \} \newline \newline // Driver code \newline int main() \newline \{ \newline int arr{[}N{]}{[}N{]} = \{ \{ 1, 2, 3, 4 \}, \newline \{ 5, 6, 7, 8 \}, \newline \{ 9, 10, 11, 12 \}, \newline \{ 13, 14, 15, 16 \} \}; \newline rotate90Clockwise(arr); \newline printMatrix(arr); \newline return 0; \newline \} \newline //anticlockwise \newline void rotateMatrix(int mat{[}{]}{[}N{]}) \newline \{ \newline // Consider all squares one by one \newline for (int x = 0; x \textless{} N / 2; x++) \{ \newline // Consider elements in group \newline // of 4 in current square \newline for (int y = x; y \textless{} N - x - 1; y++) \{ \newline // Store current cell in \newline // temp variable \newline int temp = mat{[}x{]}{[}y{]}; \newline \newline // Move values from right to top \newline mat{[}x{]}{[}y{]} = mat{[}y{]}{[}N - 1 - x{]}; \newline \newline // Move values from bottom to right \newline mat{[}y{]}{[}N - 1 - x{]} = mat{[}N - 1 - x{]}{[}N - 1 - y{]}; \newline \newline // Move values from left to bottom \newline mat{[}N - 1 - x{]}{[}N - 1 - y{]} = mat{[}N - 1 - y{]}{[}x{]}; \newline \newline // Assign temp to left \newline mat{[}N - 1 - y{]}{[}x{]} = temp; \newline \} \newline \} \newline \} \newline \newline // Function to print the matrix \newline void displayMatrix(int mat{[}N{]}{[}N{]}) \newline \{ \newline for (int i = 0; i \textless{} N; i++) \{ \newline for (int j = 0; j \textless{} N; j++) \{ \newline cout \textless{}\textless{} mat{[}i{]}{[}j{]} \textless{}\textless{} " "; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline \newline /}} Driver code {\emph{/ \newline int main() \newline \{ \newline // Test Case 1 \newline int mat{[}N{]}{[}N{]} = \{ \{ 1, 2, 3, 4 \}, \newline \{ 5, 6, 7, 8 \}, \newline \{ 9, 10, 11, 12 \}, \newline \{ 13, 14, 15, 16 \} \}; \newline \newline // Function call \newline rotateMatrix(mat); \newline \newline // Print rotated matrix \newline displayMatrix(mat); \newline \newline return 0; \newline \} \newline int binaryToDecimal(int n) \newline \{ \newline int num = n; \newline int dec\_value = 0; \newline \newline // Initializing base value to 1, i.e 2\textasciicircum{}0 \newline int base = 1; \newline \newline int temp = num; \newline while (temp) \{ \newline int last\_digit = temp \% 10; \newline temp = temp / 10; \newline \newline dec\_value += last\_digit }} base; \newline \newline base = base * 2; \newline \} \newline \newline return dec\_value; \newline \} \newline void decToBinary(int n) \newline \{ \newline // array to store binary number \newline int binaryNum{[}32{]}; \newline \newline // counter for binary array \newline int i = 0; \newline while (n \textgreater{} 0) \{ \newline \newline // storing remainder in binary array \newline binaryNum{[}i{]} = n \% 2; \newline n = n / 2; \newline i++; \newline \} \newline \newline // printing binary array in reverse order \newline for (int j = i - 1; j \textgreater{}= 0; j-{}-) \newline cout \textless{}\textless{} binaryNum{[}j{]}; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{final lab}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \#include \textless{}string\textgreater{} \newline \#include \textless{}fstream\textgreater{} \newline /{\emph{ The member function cin.getline() works with C strings (i.e. arrays of char) \newline whereas the free function std::getline() works with C++ strings (i.e. std::string.) \newline You should not be using C strings at all when learning C++, which means \newline you should not be using cin.getline().}}/ \newline using namespace std; \newline \newline void FindExt(std::string paths{[}{]}, int nPath, std::string extName, std::string results{[}{]}, int \&nRes) \newline \{ \newline nRes = 0; \newline for(int i = 0; i \textless{} nPath; i++) \newline \{ \newline string tmp = paths{[}i{]}.substr(paths{[}i{]}.find('.') + 1); \newline if(tmp == extName) \newline \{ \newline ++nRes; \newline for(int j = 0; j \textless{} nRes; j++) \newline \{ \newline results{[}j{]} = paths{[}i{]}; \newline \} \newline \} \newline \} \newline \} \newline void Find(string paths{[}{]}, int nPath, string curDir, string results{[}{]}, int \&nRes) \newline \{ \newline \newline \} \newline int main() \newline \{ \newline string paths{[}{]} = \{"D:/Others/us/b.pdf", "C:/Users/c.txt", "C:/Users/adm/a.txt", "E:/temp/d.exe"\}; \newline string extName = "txt"; \newline string results{[}1000{]}; \newline int nRes; \newline FindExt(paths, 4, extName, results, nRes); \newline for(int i = 0; i \textless{} nRes; i++) \newline \{ \newline cout \textless{}\textless{} results{[}i{]} \textless{}\textless{} " "; \newline \} \newline cout \textless{}\textless{} endl; \newline cout \textless{}\textless{} nRes; \newline return 0; \newline \} \newline \#include \textless{}iostream\textgreater{} \newline using namespace std; \newline void doMin(int a{[}{]}{[}3{]}, int m, int n) \newline \{ \newline int res{[}100{]}{[}100{]} = \{0\}; \newline \newline int toaDoX{[}8{]} = \{-1, -1, -1, 0, 0, 1, 1, 1\}; \newline int toaDoY{[}8{]} = \{-1, 0, 1, -1, 1, -1, 0, 1\}; \newline \newline for(int i = 0; i \textless{} m; ++i) \newline \{ \newline for(int j = 0; j \textless{} n; ++j) \newline \{ \newline if(a{[}i{]}{[}j{]} == 1) \newline \{ \newline for(int k = 0; k \textless{} 8; ++k) \newline \{ \newline int newX = i + toaDoX{[}k{]}; \newline int newY = j + toaDoY{[}k{]}; \newline if(newX \textgreater{}= 0 \&\& newY \textgreater{}= 0 \&\& newX \textless{} m \&\& newY \textless{} n) \newline \{ \newline ++res{[}newX{]}{[}newY{]}; \newline \} \newline \} \newline \} \newline \} \newline \} \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline a{[}i{]}{[}j{]} = res{[}i{]}{[}j{]}; \newline \} \newline \} \newline \} \newline int main() \newline \{ \newline int a{[}3{]}{[}3{]} = \{ \newline 1, 0, 0, \newline 0, 1, 0, \newline 0, 0, 0\}; \newline int m = 3; \newline int n = 3; \newline doMin(a, m, n); \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline cout \textless{}\textless{} a{[}i{]}{[}j{]} \textless{}\textless{} " "; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline return 0; \newline \} \newline \#include \textless{}iostream\textgreater{} \newline \#include \textless{}fstream\textgreater{} \newline using namespace std; \newline void ReadMap(int map{[}{]}{[}100{]}, int \&m, int \&n) \newline \{ \newline ifstream fin; \newline fin.open("map.txt"); \newline if(!fin.is\_open()) \newline \{ \newline cout \textless{}\textless{} "failed to open file!"; \newline return; \newline \} \newline fin \textgreater{}\textgreater{} m \textgreater{}\textgreater{} n; \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline fin \textgreater{}\textgreater{} map{[}i{]}{[}j{]}; \newline \} \newline \} \newline fin.close(); \newline for(int i = 0; i \textless{} m; i++) \newline \{ \newline for(int j = 0; j \textless{} n; j++) \newline \{ \newline cout \textless{}\textless{} map{[}i{]}{[}j{]} \textless{}\textless{} " "; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline \} \newline \newline int main() \newline \{ \newline int map{[}100{]}{[}100{]}; \newline int m, n; \newline ReadMap(map, m, n); \newline return 0; \newline \} \newline //các hàm \newline c\_str: string to char \newline char array to string \newline // Demonstrates conversion \newline // from character array to string \newline \newline \#include \textless{}bits/stdc++.h\textgreater{} \newline using namespace std; \newline \newline // converts character array \newline // to string and returns it \newline string convertToString(char{\emph{ a, int size) \newline \{ \newline int i; \newline string s = ""; \newline for (i = 0; i \textless{} size; i++) \{ \newline s = s + a{[}i{]}; \newline \} \newline return s; \newline \} \newline \newline // Driver code \newline int main() \newline \{ \newline char a{[}{]} = \{ 'C', 'O', 'D', 'E' \}; \newline char b{[}{]} = "geeksforgeeks"; \newline \newline int a\_size = sizeof(a) / sizeof(char); \newline int b\_size = sizeof(b) / sizeof(char); \newline \newline string s\_a = convertToString(a, a\_size); \newline string s\_b = convertToString(b, b\_size); \newline \newline cout \textless{}\textless{} s\_a \textless{}\textless{} endl; \newline cout \textless{}\textless{} s\_b \textless{}\textless{} endl; \newline \newline return 0; \newline \} \newline \newline \newline // C++ implementation of above approach \newline \#include \textless{}bits/stdc++.h\textgreater{} \newline using namespace std; \newline \newline \#define N 4 \newline \newline // Function to rotate the matrix 90 degree clockwise \newline void rotate90Clockwise(int a{[}N{]}{[}N{]}) \newline \{ \newline \newline // Traverse each cycle \newline for (int i = 0; i \textless{} N / 2; i++) \{ \newline for (int j = i; j \textless{} N - i - 1; j++) \{ \newline \newline // Swap elements of each cycle \newline // in clockwise direction \newline int temp = a{[}i{]}{[}j{]}; \newline a{[}i{]}{[}j{]} = a{[}N - 1 - j{]}{[}i{]}; \newline a{[}N - 1 - j{]}{[}i{]} = a{[}N - 1 - i{]}{[}N - 1 - j{]}; \newline a{[}N - 1 - i{]}{[}N - 1 - j{]} = a{[}j{]}{[}N - 1 - i{]}; \newline a{[}j{]}{[}N - 1 - i{]} = temp; \newline \} \newline \} \newline \} \newline \newline // Function for print matrix \newline void printMatrix(int arr{[}N{]}{[}N{]}) \newline \{ \newline for (int i = 0; i \textless{} N; i++) \{ \newline for (int j = 0; j \textless{} N; j++) \newline cout \textless{}\textless{} arr{[}i{]}{[}j{]} \textless{}\textless{} " "; \newline cout \textless{}\textless{} '\textbackslash{}n'; \newline \} \newline \} \newline \newline // Driver code \newline int main() \newline \{ \newline int arr{[}N{]}{[}N{]} = \{ \{ 1, 2, 3, 4 \}, \newline \{ 5, 6, 7, 8 \}, \newline \{ 9, 10, 11, 12 \}, \newline \{ 13, 14, 15, 16 \} \}; \newline rotate90Clockwise(arr); \newline printMatrix(arr); \newline return 0; \newline \} \newline //anticlockwise \newline void rotateMatrix(int mat{[}{]}{[}N{]}) \newline \{ \newline // Consider all squares one by one \newline for (int x = 0; x \textless{} N / 2; x++) \{ \newline // Consider elements in group \newline // of 4 in current square \newline for (int y = x; y \textless{} N - x - 1; y++) \{ \newline // Store current cell in \newline // temp variable \newline int temp = mat{[}x{]}{[}y{]}; \newline \newline // Move values from right to top \newline mat{[}x{]}{[}y{]} = mat{[}y{]}{[}N - 1 - x{]}; \newline \newline // Move values from bottom to right \newline mat{[}y{]}{[}N - 1 - x{]} = mat{[}N - 1 - x{]}{[}N - 1 - y{]}; \newline \newline // Move values from left to bottom \newline mat{[}N - 1 - x{]}{[}N - 1 - y{]} = mat{[}N - 1 - y{]}{[}x{]}; \newline \newline // Assign temp to left \newline mat{[}N - 1 - y{]}{[}x{]} = temp; \newline \} \newline \} \newline \} \newline \newline // Function to print the matrix \newline void displayMatrix(int mat{[}N{]}{[}N{]}) \newline \{ \newline for (int i = 0; i \textless{} N; i++) \{ \newline for (int j = 0; j \textless{} N; j++) \{ \newline cout \textless{}\textless{} mat{[}i{]}{[}j{]} \textless{}\textless{} " "; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline cout \textless{}\textless{} endl; \newline \} \newline \newline /}} Driver code {\emph{/ \newline int main() \newline \{ \newline // Test Case 1 \newline int mat{[}N{]}{[}N{]} = \{ \{ 1, 2, 3, 4 \}, \newline \{ 5, 6, 7, 8 \}, \newline \{ 9, 10, 11, 12 \}, \newline \{ 13, 14, 15, 16 \} \}; \newline \newline // Function call \newline rotateMatrix(mat); \newline \newline // Print rotated matrix \newline displayMatrix(mat); \newline \newline return 0; \newline \} \newline int binaryToDecimal(int n) \newline \{ \newline int num = n; \newline int dec\_value = 0; \newline \newline // Initializing base value to 1, i.e 2\textasciicircum{}0 \newline int base = 1; \newline \newline int temp = num; \newline while (temp) \{ \newline int last\_digit = temp \% 10; \newline temp = temp / 10; \newline \newline dec\_value += last\_digit }} base; \newline \newline base = base * 2; \newline \} \newline \newline return dec\_value; \newline \} \newline void decToBinary(int n) \newline \{ \newline // array to store binary number \newline int binaryNum{[}32{]}; \newline \newline // counter for binary array \newline int i = 0; \newline while (n \textgreater{} 0) \{ \newline \newline // storing remainder in binary array \newline binaryNum{[}i{]} = n \% 2; \newline n = n / 2; \newline i++; \newline \} \newline \newline // printing binary array in reverse order \newline for (int j = i - 1; j \textgreater{}= 0; j-{}-) \newline cout \textless{}\textless{} binaryNum{[}j{]}; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{vd cua convert string to char}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}iostream\textgreater{} \newline \#include \textless{}cstring\textgreater{} \newline \#include \textless{}string\textgreater{} \newline int main() \newline \{ \newline std::string s = "clc3"; \newline char cstr{[}50{]}; \newline strcpy(cstr, s.c\_str()); \newline std::cout \textless{}\textless{} cstr; \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{phoneNum}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}string\textgreater{} \newline \#include \textless{}iostream\textgreater{} \newline void readFile(string filename, Contact a{[}{]}, int \&n) \newline \{ \newline ifstream ifs; \newline ifs.open(filename.c\_str()); \newline int n = 0; \newline string s; \newline getline(ifs,s); \newline while(!if.eof()) \newline \{ \newline getline(ifs, s, '|'); \newline strcpy(a{[}n{]}.name, s.c\_str()); \newline getline(if,s, '|'); \newline a{[}n{]}.birthYear = atoi(s.c\_str()); \newline getline(ifs, s, '\textbackslash{}n'); \newline strcpy(a{[}n{]}.phoneNumber, s.c\_str()); \newline n++; \newline \} \newline ifs.close(); \newline \newline //A.I ver \newline int main() \{ \newline std::ifstream ifs("input.txt"); \newline std::vector\textless{}MyStruct\textgreater{} a; \newline std::string line; \newline \newline while (getline(ifs, line, '|')) \{ \newline MyStruct temp; \newline temp.name = line; \newline a.push\_back(temp); \newline \} \newline \} \newline void chuan\_hoa(char name{[}{]}) \newline \{ \newline for(int i = 0; name{[}i{]} != '\textbackslash{}0'; i++) \newline \{ \newline if(i == 0 || name{[}i - 1{]} == ' ') \newline \{ \newline name{[}i{]} == toupper(name{[}i{]}); \newline \} \newline else \newline \{ \newline name{[}i{]} = tolower(name{[}i{]}); \newline \} \newline \} \newline \} \newline void writeFile(string filename, Contact a{[}{]}, int n) \newline \{ \newline ofstream ofs; \newline ofs.open(filename.c\_str()) \newline \{ \newline ofs \textless{}\textless{} "name|Birth|Phone"; \newline \} \newline for(int i = 0; i \textless{} n; i++) \newline \{ \newline if(2021 - a{[}i{]}.birthYear \textgreater{} 18) \newline \{ \newline ofst \textless{}\textless{} a{[}i{]}.name \textless{}\textless{} " "; //bla bla \newline \} \newline \} \newline ofs.close(); \newline \} \newline bool soDep(char num{[}{]}) \newline \{ \newline for(int i = 3; i \textless{} strlen(num) - 1; ++i) \newline \{ \newline if(num{[}i{]} \textgreater{} num{[}i + 1{]}) \newline \{ \newline return false; \newline \} \newline \} \newline return true; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{mò 2.0 array}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{void xoayphai(int a{[}{]}, int n) \newline \{ \newline int tmp = a{[}n - 1{]}; \newline for(int i = n - 2; i \textgreater{}= 0; i-{}-) \newline \{ \newline a{[}i + 1{]} = a{[}i{]}; \newline \} \newline a{[}0{]} = tmp; \newline \} \newline //khi bắt xoay k lần, để ý là nếu k = n thì sau n lần xoay đó thì vị trí các phần tử cũng quay về lúc ban đầu nên là khi cho k thì cập nhật lại k chia dư với n thôi, và xoay với số lần đã cập nhật đó, tại vì nó giống như đồng hồ á. làm vậy nó tối ưu hơn \newline int k; \newline k \%= n; \newline for(int i = 0; i \textless{} k; i++) \newline \{ \newline xoayphai(a, n); \newline \} \newline for(int x : a) \newline \{ \newline cout \textless{}\textless{} x \textless{}\textless{} " "; \newline \} \newline \newline void xoayphai(int a{[}{]}, int n) \newline \{ \newline tmp = a{[}0{]}; \newline for (int i = 1; i \textless{} n; i++) \newline \{ \newline a{[}i{]} = a{[}i + 1{]}; \newline \} \newline a{[}1{]} = tmp; \newline \} \newline //mảng cộng dồn \newline //xây dựng mảng cộng dồn: \newline ``` \newline int f{[}n{]}; \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline if(i == 0) f{[}0{]} = a{[}0{]}; \newline else f{[}i{]} = f{[}i - 1{]} + a{[}i{]}; \newline \} \newline int q; cin \textgreater{}\textgreater{} q; \newline while (q-{}-) \newline \{ \newline int l, r; cin \textgreater{}\textgreater{} l \textgreater{}\textgreater{} r; \newline if (l == 0) cout \textless{}\textless{} f{[}r{]} \textless{}\textless{} endl; \newline else cout \textless{}\textless{} f{[}r{]} - f{[}l -1{]} \textless{}\textless{} endl; \newline \} \newline //Cho mảng số nguyên A{[}{]} gồm N phần tử, hãy tìm vị trí(bắt đầu từ 0) cuối cùng của giá trị nhỏ nhất trong mảng và vị trí đầu tiên của giá trị lớn nhất trong mảng. Tức là nếu có nhiều số có cùng giá trị nhỏ nhất bạn phải in ra ví trí cuối cùng, và có nhiều số có cùng giá trị lớn nhất trong mảng bạn phải in ra vị trí đầu tiên lớn nhất đó \newline int main() \{ \newline int n; \newline cin \textgreater{}\textgreater{} n; \newline int a{[}n{]}; \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline cin \textgreater{}\textgreater{} a{[}i{]}; \newline \} \newline int max = a{[}0{]}; \newline int min = a{[}0{]}; \newline int vtri\_max = 0; \newline int vtri\_min = 0; \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline if (a{[}i{]} \textless{}= min) //dùng dấu = để tìm ra thằng sau cùng \newline \{ \newline min = a{[}i{]}; \newline vtri\_min = i; \newline \} \newline if (a{[}i{]} \textgreater{} max) //không được dùng dấu = vì nếu nó bằng thì vtri\_max sẽ bị cập nhật thành the current i, nói chung cái nào bự thì đừng bằng(?) \newline \{ \newline max = a{[}i{]}; \newline vtri\_max = i; \newline \} \newline \} \newline cout \textless{}\textless{} vtri\_min \textless{}\textless{} " " \textless{}\textless{} vtri\_max; \newline \newline \newline return 0; \newline \} \newline //đề: Cho mảng số nguyên A{[}{]} gồm N phần tử, hãy liệt kê theo thứ tự xuất hiện các số thỏa mãn có ít nhất 1 số trái dấu với nó đứng cạnh nó. \newline - ý tưởng: ta thấy: chỉ cần a{[}i{]} {\emph{ a{[}i + 1{]} \textless{} 0 hay a{[}i{]} }} a{[}i -1{]} \textless{} 0 thì thỏa mãn \newline do số liền kề với i là i + 1 và i - 1. xét các trường hợp khi i là 0 và i là n - 1 và các trường hợp (bth) còn lại \newline for (int i = 0; i \textless{} n; i++) \newline \{ \newline if(i == 0) \newline \{ \newline if(a{[}0{]} {\emph{ a{[}1{]} \textless{} 0) cout \textless{}\textless{} a{[}0{]} \textless{}\textless{} " "; \newline \} \newline else if(i == n - 1) \newline \{ \newline if(a{[}n - 1{]} }} a{[}n - 2{]} \textless{} 0) cout \textless{}\textless{} a{[}n - 1{]} \textless{}\textless{} " "; \newline \} \newline else \newline \{ \newline if(a{[}i{]} {\emph{ a{[}i - 1{]} \textless{} 0 || a{[}i{]} }} a{[}i + 1{]} \textless{} 0) cout \textless{}\textless{} a{[}i{]} \textless{}\textless{} " "; \newline \} \newline \} \newline ```} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ato đồ đó}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{atoi -\textgreater{} ASCII to integer. \newline atol -\textgreater{} ASCII to long. \newline atof -\textgreater{} ASCII to floating. \newline stoi -\textgreater{} string to integer. \newline stol -\textgreater{} string to long. \newline stoll -\textgreater{} string to long long. \newline stof -\textgreater{} string to float. \newline stod -\textgreater{} string to double. \newline stold -\textgreater{} string to long double.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}