daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int lubCount(0), spaceCount(0), tmpSpaceCount(0);
  8.     string word = "";
  9.  
  10.     ifstream file("plik.txt");
  11.  
  12.     while (file.good() && word != "lub")
  13.     {
  14.         file >> word;
  15.         cout << word << endl;
  16.     }
  17.     lubCount++;
  18.     tmpSpaceCount++;
  19.  
  20.     file >> word;
  21.     while (file.good())
  22.     {
  23.         cout << word << endl;
  24.         if(word == "lub") {
  25.             lubCount++;
  26.             spaceCount += tmpSpaceCount;
  27.             cout << "spaceCount = " << spaceCount << endl;
  28.             tmpSpaceCount = 1;
  29.         }
  30.         else
  31.         {
  32.             tmpSpaceCount++;
  33.         }
  34.         file >> word;
  35.     }
  36.  
  37.     cout << "Średnia odległość " << spaceCount << " / " << lubCount << " = " << (float)spaceCount / (lubCount-1) << endl;
  38.  
  39.     file.close();
  40.  
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top