Advertisement
xTheEc0

5. Pieštukai (Vad 96. psl.)

Feb 9th, 2015
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. /*
  2. 3
  3. Melynas             9 P B L D B P L P B
  4. Raudonas            15 D B D B D B D L D B D B D B L
  5. Sviesiai zalias     1 P
  6. */
  7.  
  8. #include <iostream>
  9. #include <iomanip>
  10. #include <fstream>
  11. using namespace std;
  12.  
  13. const char duomF[] = "1.txt";
  14. const char rezF[] = "rez1.txt";
  15. const int CMax = 101;
  16. const int CPav = 20;
  17.  
  18. struct piestukai
  19. {
  20.     string pav;
  21.     double ilgis;
  22.     char raide;
  23. };
  24.  
  25. void reset(piestukai A[])
  26. {
  27.     for (int i = 0; i < CMax; i++)
  28.     {
  29.         A[i].ilgis = 150;
  30.     }
  31. }
  32.  
  33. void skaitymas(piestukai A[], int &n)
  34. {
  35.     ifstream df(duomF);
  36.     char eil[CPav + 1];
  37.     char temp;
  38.     int p;
  39.  
  40.     df >> n;
  41.     for (int i = 0; i < n; i++)
  42.     {
  43.         df.ignore(80, '\n');
  44.         df.get(eil, CPav);
  45.         A[i].pav = eil;
  46.  
  47.         df >> p;
  48.         for (int j = 0; j < p; j++)
  49.         {
  50.             df >> temp;
  51.             A[j].raide = temp;
  52.  
  53.             if (A[j].raide == 'P') A[i].ilgis -= 10;
  54.             else if (A[j].raide == 'D') A[i].ilgis -= 7;
  55.             else if (A[j]. raide == 'B')
  56.             {
  57.                 if (A[j-1].raide == 'P') A[i].ilgis -= 7;
  58.                 else if (A[j-1].raide == 'D') A[i].ilgis -= 5;
  59.             }
  60.         }
  61.     }
  62.     df.close();
  63. }
  64.  
  65. int main ()
  66. {
  67.     piestukai A[CMax];
  68.     int n;
  69.  
  70.     reset(A);
  71.     skaitymas(A, n);
  72.     for(int i = 0; i < n; i++) cout << A[i].pav << A[i].ilgis << endl;
  73.  
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement