fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. void word_to_bool(string word, bool letters[]) {
  7. for (char c : word) {
  8. if (isalpha(c)) {
  9. letters[tolower(c) - 'a'] = true;
  10. }
  11. }
  12. }
  13.  
  14. int count_letters(bool letters[]) {
  15. int count = 0;
  16. for (int i = 0; i < 26; i++) {
  17. if (letters[i]) {
  18. count++;
  19. }
  20. }
  21. return count;
  22. }
  23.  
  24. int main() {
  25. // freopen("input.txt", "r", stdin);
  26. // freopen("output.txt", "w", stdout);
  27. bool max_letters[26] = {0};
  28. int max_count = 0;
  29. string max_words = "";
  30. string line;
  31. if (line == "") {
  32. cout << "NULL\n";
  33. return 0;
  34. }
  35. while (getline(cin, line)) {
  36. int start = 0;
  37. for (int i = 0; i <= line.size(); i++) {
  38. if (i == line.size() || ispunct(line[i]) || isspace(line[i])) {
  39. string word = line.substr(start, i - start);
  40. bool letters[26] = {0};
  41. word_to_bool(word, letters);
  42. int count = count_letters(letters);
  43. if (count > max_count) {
  44. max_count = count;
  45. max_words = word;
  46. }
  47. else if (count == max_count) {
  48. max_words += " " + word;
  49. }
  50. start = i + 1;
  51. }
  52. }
  53. }
  54. if (max_count == 0) {
  55. cout << "-1\n";
  56. }
  57.  
  58. else {
  59. cout << max_words << "\n";
  60. }
  61. return 0;
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
NULL