fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 2000;
  6.  
  7. bool hasDistinctLetters(char word[], int len) {
  8. const int LAST_LETTER = 'z';
  9. int fr[LAST_LETTER] = {0};
  10. for (int i = 0; i < len; ++i) {
  11. ++fr[word[i]];
  12. if (fr[word[i]] > 1) {
  13. return false;
  14. }
  15. }
  16. return true;
  17. }
  18.  
  19. bool moreAbsurd(char firstWord[], char secondWord[]) {
  20. int firstLen = strlen(firstWord), secondLen = strlen(secondWord);
  21. return hasDistinctLetters(firstWord, firstLen) && (firstLen > secondLen || (firstLen == secondLen && strcmp(firstWord, secondWord) < 0));
  22. }
  23.  
  24. bool isLetter(char c) {
  25. return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
  26. }
  27.  
  28. void distinctLettersLargestWord(char absurdWord[], char text[]) {
  29. int n = strlen(text);
  30. char currentWord[MAX_SIZE + 1] = {0};
  31. bool wasWord = false;
  32. for (int i = 0; i <= n; ++i) {
  33. if (isLetter(text[i])) {
  34. char letter[] = {text[i], 0};
  35. strcat(currentWord, letter);
  36. wasWord = true;
  37. } else if (wasWord) {
  38. if (moreAbsurd(currentWord, absurdWord)) {
  39. strcpy(absurdWord, currentWord);
  40. }
  41. currentWord[0] = 0;
  42. wasWord = false;
  43. }
  44. }
  45. }
  46.  
  47. int main() {
  48. char text[MAX_SIZE + 1], absurdWord[MAX_SIZE + 1] = {0};
  49. while (cin.getline(text, MAX_SIZE + 1)) {
  50. distinctLettersLargestWord(absurdWord, text);
  51. }
  52. if (absurdWord[0]) {
  53. cout << absurdWord;
  54. } else {
  55. cout << "Ist nicht vorhanden!";
  56. }
  57. return 0;
  58. }
Success #stdin #stdout 0.01s 5288KB
stdin
aa b bd

stdout
bd