Advertisement
Graf_Rav

huinya2

Jan 11th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.     setlocale(LC_ALL, "Russian");
  8.  
  9.     string input;
  10.     getline(cin, input);
  11.  
  12.     int wordLength = 0;
  13.     int fullLength = 0;
  14.     int wordsCount = 0;
  15.  
  16.     for(int i = 0; i < input.length(); i++){
  17.         if(input[i] != ' ' && input[i] != ','){
  18.             wordLength++;
  19.         }
  20.         else{
  21.             if(wordLength != 0){
  22.                 fullLength += wordLength;
  23.                 wordsCount++;
  24.             }
  25.             wordLength = 0;
  26.         }
  27.     }
  28.     if(wordLength != 0){
  29.         fullLength += wordLength;
  30.         wordsCount++;
  31.     }
  32.  
  33.     if(wordsCount == 0){
  34.         cout<<"Слов нет";
  35.     }
  36.     else{
  37.         cout<<"Средняя длина слова "<<((double)fullLength)/wordsCount;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement