Advertisement
muhata84

07. The Noise and the Signal

Oct 9th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <string.h>
  5. #include <algorithm>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. string inPut;
  13. getline(cin,inPut);
  14.  
  15. istringstream ss(inPut);
  16. string word;
  17. vector<string> vec;
  18. vector<int> word_size;
  19.  
  20. while(ss >> word)
  21. {
  22. string remove_number = "";
  23. for (char c : word)
  24. {
  25. if (!std::isdigit(c))
  26. {
  27. remove_number += c;
  28. }
  29. }
  30. if(remove_number.size() > 0)
  31. {
  32. vec.push_back(remove_number);
  33. }
  34. }
  35.  
  36. int max_length = 0;
  37. for(auto i : vec)
  38. {
  39. if(max_length < i.length())
  40. {
  41. max_length = i.length();
  42. }
  43. }
  44.  
  45. vector<string> max_word;
  46.  
  47. for(int i =0; i < vec.size(); i++)
  48. {
  49. string max_string;
  50. max_string = vec[i];
  51.  
  52. if(max_length == max_string.size())
  53. {
  54. max_word.push_back(max_string);
  55. }
  56. }
  57.  
  58. sort(max_word.begin(),max_word.end());
  59.  
  60. if(vec.size() == 0)
  61. {
  62. cout<<"no noise";
  63. }
  64. else
  65. {
  66. cout<<max_word[0];
  67. }
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement