fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool isValid(int frq[], string word) {
  6. for (int i = 0; i <= 'z'; ++i) {
  7. frq[i] = 0;
  8. }
  9. for (int i = 0; i < word.size(); ++i) {
  10. ++frq[word[i]];
  11. if (frq[word[i]] > 1) {
  12. return false;
  13. }
  14. }
  15. return true;
  16. }
  17.  
  18.  
  19. int main() {
  20. string text;
  21. string maxWord = "";
  22. while (getline(cin, text)) {
  23. int len = (int)text.size();
  24. string currWord = "";
  25. for (int i = 0; i <= len; ++i) {
  26. if (isalpha(text[i])) {
  27. currWord += text[i];
  28. } else if (!currWord.empty()) {
  29. int frq['z' + 1] = {0};
  30. int index = 0;
  31. string currMax = "";
  32. while (frq[currWord[index]] == 0) {
  33. ++frq[currWord[index]];
  34. if (frq[currWord[index]] == 1) {
  35. currMax += currMax[index];
  36. }
  37. ++index;
  38. }
  39. i += (index - 1);
  40. if (currMax.size() > maxWord.size() || (currMax.size() == maxWord.size() && currMax < maxWord)) {
  41. maxWord = currMax;
  42. }
  43. currWord.clear();
  44. }
  45. }
  46. for (int k = 0; k < maxWord.size(); ++k) {
  47. cout << maxWord[k];
  48. }
  49. }
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0.01s 5296KB
stdin
Aabcadefg…abcd
!xyzd!!! xyxzd
stdout