We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#include <bits/stdc++.h> using namespace std; string ltrim(const string &); string rtrim(const string &); vector<string> split(const string &); /* * Complete the 'compareTriplets' function below. * * The function is expected to return an INTEGER_ARRAY. * The function accepts following parameters: * 1. INTEGER_ARRAY a * 2. INTEGER_ARRAY b */ vector<int> compareTriplets(vector<int> a, vector<int> b) { vector<int> result(2, 0); if (a.size() != b.size()) { return result; } for (int i = 0; i < a.size(); i++) { if (a[i] > b[i]) { result[0]++; } else if (a[i] < b[i]) { result[1]++; } } return result; } int main() { ofstream fout(getenv("OUTPUT_PATH")); string a_temp_temp; getline(cin, a_temp_temp); vector<string> a_temp = split(rtrim(a_temp_temp)); vector<int> a(3); for (int i = 0; i < 3; i++) { int a_item = stoi(a_temp[i]); a[i] = a_item; } string b_temp_temp; getline(cin, b_temp_temp); vector<string> b_temp = split(rtrim(b_temp_temp)); vector<int> b(3); for (int i = 0; i < 3; i++) { int b_item = stoi(b_temp[i]); b[i] = b_item; } vector<int> result = compareTriplets(a, b); for (size_t i = 0; i < result.size(); i++) { fout << result[i]; if (i != result.size() - 1) { fout << " "; } } fout << "\n"; fout.close(); return 0; } string ltrim(const string &str) { string s(str); s.erase( s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace))) ); return s; } string rtrim(const string &str) { string s(str); s.erase( find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(), s.end() ); return s; } vector<string> split(const string &str) { vector<string> tokens; string::size_type start = 0; string::size_type end = 0; while ((end = str.find(" ", start)) != string::npos) { tokens.push_back(str.substr(start, end - start)); start = end + 1; } tokens.push_back(str.substr(start)); return tokens; }
The text was updated successfully, but these errors were encountered:
fkdl0048
No branches or pull requests
The text was updated successfully, but these errors were encountered: