From e71a4c24049ca2c73e79c3495b7ef69f81c222b8 Mon Sep 17 00:00:00 2001 From: Yash Raj Pandey <55940078+devYRPauli@users.noreply.github.com> Date: Thu, 1 Oct 2020 13:03:48 +0530 Subject: [PATCH] Create solution.cpp --- .../solution.cpp | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Hacker-Rank/30-Days-of-Code/RegEx, Patterns, and Intro to Databases/solution.cpp diff --git a/Hacker-Rank/30-Days-of-Code/RegEx, Patterns, and Intro to Databases/solution.cpp b/Hacker-Rank/30-Days-of-Code/RegEx, Patterns, and Intro to Databases/solution.cpp new file mode 100644 index 0000000..dcc2a30 --- /dev/null +++ b/Hacker-Rank/30-Days-of-Code/RegEx, Patterns, and Intro to Databases/solution.cpp @@ -0,0 +1,56 @@ +#include + +using namespace std; + +vector split_string(string); + + + +int main() +{ + int N; + cin >> N; + cin.ignore(numeric_limits::max(), '\n'); + + for (int N_itr = 0; N_itr < N; N_itr++) { + string firstNameEmailID_temp; + getline(cin, firstNameEmailID_temp); + + vector firstNameEmailID = split_string(firstNameEmailID_temp); + + string firstName = firstNameEmailID[0]; + + string emailID = firstNameEmailID[1]; + } + + return 0; +} + +vector split_string(string input_string) { + string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) { + return x == y and x == ' '; + }); + + input_string.erase(new_end, input_string.end()); + + while (input_string[input_string.length() - 1] == ' ') { + input_string.pop_back(); + } + + vector splits; + char delimiter = ' '; + + size_t i = 0; + size_t pos = input_string.find(delimiter); + + while (pos != string::npos) { + splits.push_back(input_string.substr(i, pos - i)); + + i = pos + 1; + pos = input_string.find(delimiter, i); + } + + splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1)); + + return splits; +}