From 65eaf954ca2f3065de8d2e69568991b911b5ada8 Mon Sep 17 00:00:00 2001 From: Srijan Date: Fri, 2 Oct 2020 15:40:53 +0530 Subject: [PATCH] Added ALgorithms --- Languages/C++/Max. substring in string.cpp | 20 ++++++++++++++++++++ Languages/C++/half-star pattern.cpp | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Languages/C++/Max. substring in string.cpp create mode 100644 Languages/C++/half-star pattern.cpp diff --git a/Languages/C++/Max. substring in string.cpp b/Languages/C++/Max. substring in string.cpp new file mode 100644 index 000000000..07e25be32 --- /dev/null +++ b/Languages/C++/Max. substring in string.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +string MaxString(string str) +{ + // loop to find the max leicographic + // substring in the substring array + string mx = ""; + for (int i = 0; i < str.length(); ++i) + mx = max(mx, str.substr(i)); + + return mx; +} + +int main() +{ + string str = "ababaa"; + cout << MaxString(str); + return 0; +} \ No newline at end of file diff --git a/Languages/C++/half-star pattern.cpp b/Languages/C++/half-star pattern.cpp new file mode 100644 index 000000000..e4108355f --- /dev/null +++ b/Languages/C++/half-star pattern.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +int main() +{ +int i, j, n; +cout << "Enter number of rows: "; +cin >> n; +for(i = 1; i <= n; i++) +{ +for(j = 1; j <= i; j++) +{ +cout << "* "; +} +//Ending line after each row +cout << "\n"; +} +return 0; +} \ No newline at end of file