Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main() {
- int lubCount(0), spaceCount(0), tmpSpaceCount(0);
- string word = "";
- ifstream file("plik.txt");
- while (file.good() && word != "lub")
- {
- file >> word;
- cout << word << endl;
- }
- lubCount++;
- tmpSpaceCount++;
- file >> word;
- while (file.good())
- {
- cout << word << endl;
- if(word == "lub") {
- lubCount++;
- spaceCount += tmpSpaceCount;
- cout << "spaceCount = " << spaceCount << endl;
- tmpSpaceCount = 1;
- }
- else
- {
- tmpSpaceCount++;
- }
- file >> word;
- }
- cout << "Średnia odległość " << spaceCount << " / " << lubCount << " = " << (float)spaceCount / (lubCount-1) << endl;
- file.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment