diff --git a/Algorithms/Happy Ladybugs.cpp b/Algorithms/Happy Ladybugs.cpp new file mode 100644 index 0000000..6c7662b --- /dev/null +++ b/Algorithms/Happy Ladybugs.cpp @@ -0,0 +1,74 @@ +#include + +using namespace std; + +// Complete the happyLadybugs function below. +string happyLadybugs(string b) +{ + int a[26]={0}; + int i,l=0,c=0; + + for(i=0;i0)) + l++; + } + } + if(c > 0) + { + for(i=0;i<26;i++) + { + if(a[i]==1) + break; + } + if(i<26) + return "NO"; + else + return "YES"; + } + else + { + if(b.size()== 1 && b[0]!='_') + return "NO"; + else + { + if(l == b.size()) + return "YES"; + else + return "NO"; + } + + } + +} + +int main() +{ + ofstream fout(getenv("OUTPUT_PATH")); + + int g; + cin >> g; + cin.ignore(numeric_limits::max(), '\n'); + + for (int g_itr = 0; g_itr < g; g_itr++) { + int n; + cin >> n; + cin.ignore(numeric_limits::max(), '\n'); + + string b; + getline(cin, b); + + string result = happyLadybugs(b); + + fout << result << "\n"; + } + + fout.close(); + + return 0; +} diff --git a/Algorithms/Running Time of Algorithms.cpp b/Algorithms/Running Time of Algorithms.cpp new file mode 100644 index 0000000..1c43302 --- /dev/null +++ b/Algorithms/Running Time of Algorithms.cpp @@ -0,0 +1,93 @@ +#include + +using namespace std; + +vector split_string(string); + +// Complete the runningTime function below. +int runningTime(vector arr) +{ + int i,j,k,s=0; + for(i=0;i<(arr.size()-1);i++) + { + int c=0,k=arr[i+1]; + for(j=i;j>=0;j--) + { + if(arr[j] > k) + { + c++; + arr[j+1]=arr[j]; + + } + else + { + arr[j+1]=k; + break; + } + } + if(j==-1) + arr[0]=k; + + s = s+c; + } + return s; +} + +int main() +{ + ofstream fout(getenv("OUTPUT_PATH")); + + int n; + cin >> n; + cin.ignore(numeric_limits::max(), '\n'); + + string arr_temp_temp; + getline(cin, arr_temp_temp); + + vector arr_temp = split_string(arr_temp_temp); + + vector arr(n); + + for (int i = 0; i < n; i++) { + int arr_item = stoi(arr_temp[i]); + + arr[i] = arr_item; + } + + int result = runningTime(arr); + + fout << result << "\n"; + + fout.close(); + + 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; +}