fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <set>
  4. #include <string>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. bool has_all_distinct_letters(const std::string& word) {
  9. std::set<char> letters;
  10. for (char c : word) {
  11. if (letters.find(c) != letters.end()) {
  12. return false; // If the letter already exists, return false
  13. }
  14. letters.insert(c);
  15. }
  16. return true; // All letters are distinct
  17. }
  18.  
  19. int main() {
  20. std::string line;
  21. std::vector<std::string> words;
  22.  
  23. // Citirea textului de intrare
  24. while (std::getline(std::cin, line)) {
  25. std::istringstream stream(line);
  26. std::string word;
  27. while (stream >> word) {
  28. words.push_back(word);
  29. }
  30. }
  31.  
  32. std::string longest_distinct_word;
  33.  
  34. // Căutarea celui mai lung cuvânt cu litere distincte
  35. for (const std::string& word : words) {
  36. if (has_all_distinct_letters(word) && word.length() > longest_distinct_word.length()) {
  37. longest_distinct_word = word;
  38. }
  39. }
  40.  
  41. if (!longest_distinct_word.empty()) {
  42. std::cout << longest_distinct_word << std::endl;
  43. } else {
  44. std::cout << "Ist nicht vorhanden!" << std::endl;
  45. }
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 5292KB
stdin
Aabcadefg…abcd
!xyzd!!! xyxzd
stdout
Ist nicht vorhanden!