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. if (strlen(lexicoSmall) == 0 || strcmp(lexicoSmall, text) > 0) {
  9. strcpy(lexicoSmall, text);
  10. }
  11. }
  12.  
  13. bool haveDistinctLetters(char text[]) {
  14. const int MAX_SIZE = (int)'z';
  15. int textLen = strlen(text), fr[MAX_SIZE + 1] = {0};
  16. for (int i = 0; i < textLen; ++i) {
  17. ++fr[(int)text[i]];
  18. if (fr[(int)text[i]] > 1) {
  19. return false;
  20. }
  21. }
  22. return true;
  23. }
  24.  
  25. void findLargerDistinct(char lexicoLarge[], char text[]) {
  26. if (haveDistinctLetters(text) && (strlen(lexicoLarge) == 0 || strcmp(lexicoLarge, text) < 0)) {
  27. strcpy(lexicoLarge, text);
  28. }
  29. }
  30.  
  31. int main() {
  32. char text[MAX_SIZE + 1], lexicoSmall[MAX_SIZE + 1] = "", lexicoLarge[MAX_SIZE + 1] = "";
  33. while (cin >> text) {
  34. copySmaller(lexicoSmall, text);
  35. findLargerDistinct(lexicoLarge, text);
  36. }
  37. if (strlen(lexicoLarge)) {
  38. cout << lexicoLarge;
  39. } else {
  40. cout << lexicoSmall;
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5268KB
stdin
Aac
Bbe
Ccn
stdout
Ccn