fork(3) download
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. #define is_delim(c) (isspace((c)) || ispunct((c)))
  5.  
  6. void input_words(std::istream& _in, std::string& minw, std::string& maxw){
  7. std::string s;
  8. char c;
  9. int e, k = 0;
  10.  
  11. do {
  12. _in.get(c);
  13. e = _in.eof();
  14. if(is_delim(c) || e){
  15. if(k){
  16. if((s.length() < minw.length()) || !minw.length())
  17. minw = s;
  18. if(s.length() > maxw.length())
  19. maxw = s;
  20. }
  21. s = "";
  22. k = 0;
  23. } else {
  24. k = 1;
  25. s += c;
  26. }
  27. if(c == '\n' || c == '\r')
  28. break;
  29. } while(! e && ! _in.fail());
  30. }
  31.  
  32.  
  33. int main(void){
  34. std::string minw, maxw;
  35. input_words(std::cin, minw, maxw);
  36. std::cout << "min word: " << minw << std::endl;
  37. std::cout << "max word: " << maxw << std::endl;
  38. return 0;
  39. }
Success #stdin #stdout 0s 3460KB
stdin
Ввести строку, содержащую несколько слов
stdout
min word: слов
max word: содержащую