fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 100;
  6.  
  7. void copySmaller(char lexicoSmall[], char text[]) {
  8. int smallerLen = strlen(lexicoSmall);
  9. if (smallerLen == 0 || smallerLen > strlen(text)) {
  10. strcpy(lexicoSmall, text);
  11. }
  12. }
  13.  
  14. bool haveDistinctLetters(char text[]) {
  15. const int MAX_SIZE = (int)'z';
  16. int textLen = strlen(text), fr[MAX_SIZE + 1] = {0};
  17. for (int i = 0; i < textLen; ++i) {
  18. ++fr[(int)text[i]];
  19. if (fr[(int)text[i]] > 1) {
  20. return false;
  21. }
  22. }
  23. return true;
  24. }
  25.  
  26. void findLargerDistinct(char lexicoLarge[], char text[]) {
  27. int largeLen = strlen(lexicoLarge);
  28. if (haveDistinctLetters(text) && (largeLen == 0 || largeLen < strlen(text))) {
  29. strcpy(lexicoLarge, text);
  30. }
  31. }
  32.  
  33. int main() {
  34. char text[MAX_SIZE + 1], lexicoSmall[MAX_SIZE + 1] = "", lexicoLarge[MAX_SIZE + 1] = "";
  35. while (cin >> text) {
  36. copySmaller(lexicoSmall, text);
  37. findLargerDistinct(lexicoLarge, text);
  38. }
  39. if (strlen(lexicoLarge)) {
  40. cout << lexicoLarge;
  41. } else {
  42. cout << lexicoSmall;
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5284KB
stdin
a
b
c
stdout
a