PhotoShaman

Laba10Tasks

Feb 7th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. //1 Вариант
  2. ----------------------------------------
  3. #include <iostream>
  4. #include <string>
  5. #include <clocale>
  6. #include <windows.h>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11. void main()
  12. {
  13.     SetConsoleCP(1251);
  14.     SetConsoleOutputCP(1251);
  15.     ifstream Fin; // поток ввода
  16.     ofstream Fout; // поток вывода
  17.     Fin.open("C:\\Users\\User\\Desktop\\text.txt");
  18.     Fout.open("C:\\Users\\User\\Desktop\\OutputText.txt");
  19.     string line;
  20.     while (getline(Fin, line))
  21.     {
  22.         int wordCount = 0, currentPosition = 0;
  23.         while (line[currentPosition] == ' ' && line[currentPosition] != '\0')
  24.             currentPosition++; //Проходит пробелы в начале строки
  25.         bool isWord = false;
  26.         while (line[currentPosition] != '\0')
  27.         {
  28.             if (line[currentPosition] != ' ' && !isWord)
  29.             {
  30.                 isWord = true;
  31.                 wordCount++;
  32.             }
  33.             else if (line[currentPosition] == ' ')
  34.                 isWord = false;
  35.             currentPosition++;
  36.         }
  37.         Fout << wordCount << endl;
  38.     }
  39.     Fout.close();
  40.     Fin.close();
  41.     cout << "Программа закончила работу!\n";
  42.     system("pause");
  43. }
  44. //Дополнительно
  45. ----------------------------------------
  46. #include <iostream>
  47. #include <string>
  48. #include <clocale>
  49. #include <windows.h>
  50. #include <fstream>
  51.  
  52. using namespace std;
  53.  
  54. void main()
  55. {
  56.     SetConsoleCP(1251);
  57.     SetConsoleOutputCP(1251);
  58.     ifstream Fin; // поток ввода
  59.     ofstream Fout; // поток вывода
  60.     Fin.open("C:\\Users\\User\\Desktop\\LessonsList.txt");
  61.     Fout.open("C:\\Users\\User\\Desktop\\OutputInfo.txt");
  62.  
  63.     string line;
  64.     int lectureCount = 0, laboratoryWorkCount = 0, practicalWorkCount = 0;
  65.  
  66.     while (getline(Fin, line))
  67.     {
  68.         if ((line.find("лекц")) != string::npos) lectureCount++;
  69.         else if ((line.find("лаб")) != string::npos) laboratoryWorkCount++;
  70.         else if ((line.find("практ")) != string::npos) practicalWorkCount++;
  71.     }
  72.     Fout << "Лекций: " << lectureCount << endl;
  73.     Fout << "Лабораторных: " << laboratoryWorkCount << endl;
  74.     Fout << "Практических: " << practicalWorkCount << endl;
  75.  
  76.     Fout.close();
  77.     Fin.close();
  78.     cout << "Программа закончила работу!" << endl;
  79.     system("pause");
  80. }
Advertisement
Add Comment
Please, Sign In to add comment