Advertisement
Spocoman

04. Some Ordering

Feb 9th, 2024 (edited)
1,119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <memory>
  4.  
  5. using namespace std;
  6.  
  7. unique_ptr<char[]> transform(const char* text, const int& n, char (*transformFunc)(const char&)) {
  8.     unique_ptr<char[]> result = make_unique<char[]>(n);
  9.  
  10.     for (int i = 0; i < n; i++) {
  11.         result[i] = transformFunc(text[i]);
  12.     }
  13.     return result;
  14. }
  15.  
  16. int main()
  17. {
  18.     string input;
  19.     getline(cin, input);
  20.  
  21.     unique_ptr<char[]> lowerValue = transform(input.c_str(), input.length() + 1, [](const char& s) { return (char)tolower(s); });
  22.     cout << lowerValue.get() << endl;
  23.  
  24.     unique_ptr<char[]> upperValue = transform(input.c_str(), input.length() + 1, [](const char& s) { return (char)toupper(s); });
  25.     cout << upperValue.get() << endl;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement