Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main(){
- setlocale(LC_ALL, "Russian");
- string input;
- getline(cin, input);
- int wordLength = 0;
- int fullLength = 0;
- int wordsCount = 0;
- for(int i = 0; i < input.length(); i++){
- if(input[i] != ' ' && input[i] != ','){
- wordLength++;
- }
- else{
- if(wordLength != 0){
- fullLength += wordLength;
- wordsCount++;
- }
- wordLength = 0;
- }
- }
- if(wordLength != 0){
- fullLength += wordLength;
- wordsCount++;
- }
- if(wordsCount == 0){
- cout<<"Слов нет";
- }
- else{
- cout<<"Средняя длина слова "<<((double)fullLength)/wordsCount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement