diff options
author | Oskar <[email protected]> | 2024-08-30 15:14:27 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-30 15:14:27 +0200 |
commit | 2952047fe741ca5b3717e066e0a6aeac699ee4c1 (patch) | |
tree | 4cb263498f347107142a4de9b80812748f03423f /5p14.cpp | |
parent | e039d589d29ab799c20fe845d5a005dc257f9a44 (diff) |
more
Diffstat (limited to '5p14.cpp')
-rw-r--r-- | 5p14.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/5p14.cpp b/5p14.cpp new file mode 100644 index 0000000..5c032e1 --- /dev/null +++ b/5p14.cpp @@ -0,0 +1,45 @@ +#include <iostream> + +/* + * + * 5.14 + * + * The program does not handle cases where words repeat for + * the same amount of times. So for example if we input + * "hello hello hi hi" only hello would print as the top word + */ + +int main () { + + std::string NewWord; + std::string TempWord; + std::string MostOccuring; + uint32_t TmpCount = 0; + uint32_t TopCount = 0; + while(std::cin >> NewWord) { + if(TempWord != NewWord) { + if(TmpCount > TopCount) { + TopCount = TmpCount; + MostOccuring = TempWord; + } + + TempWord = NewWord; + TmpCount = 1; + } else if(TempWord == NewWord) { + ++TmpCount; + if(TmpCount > TopCount) { + TopCount = TmpCount; + MostOccuring = TempWord; + } + } + } + + + if(TopCount > 1) { + std::cout << MostOccuring << " is the top word occuring " << TopCount << " times." << std::endl; + } else { + std::cout << "No words were repeated!" << std::endl; + } + + return 0; +} |