Advertisement
bobo_bobkata

Untitled

Oct 6th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <iterator>
  4.  
  5. std::vector<std::string> splitInput(const std::string &line);
  6.  
  7. std::vector<std::string> extractCorrectValues(const std::vector<std::string> &results);
  8.  
  9. std::string getString(const std::vector<std::string> &values);
  10.  
  11. int main() {
  12. std::string line;
  13. std::getline(std::cin, line);
  14.  
  15. std::vector<std::string> results = splitInput(line);
  16.  
  17. std::vector<std::string> correctResults = extractCorrectValues(results);
  18.  
  19. std::string toPrint = getString(correctResults);
  20.  
  21. std::cout << toPrint << std::endl;
  22. return 0;
  23. }
  24.  
  25. std::string getString(const std::vector<std::string> &values) {
  26. std::string toReturn = "";
  27. for (const auto &value : values) {
  28. if (value.length() > toReturn.length()) {
  29. toReturn = value;
  30. } else if (value.length() == toReturn.length()) {
  31. char fChar = value.at(0);
  32. char sChar = toReturn.at(0);
  33. if (fChar < sChar) {
  34. toReturn = value;
  35. }
  36. }
  37. }
  38. if (toReturn.empty()) {
  39. toReturn = "no noise";
  40. }
  41. return toReturn;
  42. }
  43.  
  44. std::vector<std::string> extractCorrectValues(const std::vector<std::string> &results) {
  45. std::vector<std::string> correctValues;
  46. for (const auto &currentString : results) {
  47. std::string extractedString = "";
  48. for (char j : currentString) {
  49. if (!isdigit(j)) {
  50. extractedString += j;
  51. }
  52. }
  53. if (!extractedString.empty()) {
  54. correctValues.push_back(extractedString);
  55. }
  56. }
  57. return correctValues;
  58. }
  59.  
  60. std::vector<std::string> splitInput(const std::string &line) {
  61. std::istringstream iss(line);
  62. std::vector<std::string> results(std::istream_iterator<std::string>{iss}, std::istream_iterator<std::string>());
  63. return results;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement