Facebook
From Unreliable Hamerkop, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 52
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. const char CDfv[] = "D.txt";
  8. const char CRfv[] = "R.txt";
  9. const int CMax = 100;
  10.  
  11. void Skaityti(const char fv[], char A[], int B[], int & n);
  12. void Spausdinti(const char fv[], char A[], int B[], int n);
  13. int IeskotiBatu(char A[], int B[], int n, char tp, int dd);
  14. void SalintiBatus (char A[], int B[], int & n, int ind);
  15.  
  16. int main()
  17. {
  18.     char T[CMax];
  19.     int D[CMax];
  20.     int n;
  21.     int bind;
  22.     ofstream fr;
  23.  
  24.     Skaityti(CDfv, T, D, n);
  25.     cout << n << endl;
  26.     fr.open(CRfv); fr.close();
  27.     Spausdinti(CRfv, T, D, n);
  28.  
  29.     fr.open(CRfv, ios::app);
  30.     bind = IeskotiBatu(T, D, n, 'v', 43);
  31.     if (bind >= 0)
  32.     {
  33.         fr << "Mykolo 43-io dydzio batu indeksas masyve " << bind << endl;
  34.         SalintiBatus(T, D, n, bind);
  35.     }
  36.     else
  37.     {
  38.         fr << "Parduotuveja Mykolo 43-io dydzio batu nebuvo" << endl;
  39.     }
  40.  
  41.     bind = IeskotiBatu(T, D, n, 'm', 38);
  42.     if (bind >= 0)
  43.     {
  44.         fr << "Marytes 38-io dydzio batu indeksas masyve " << bind << endl;
  45.         SalintiBatus(T, D, n, bind);
  46.     }
  47.     else
  48.     {
  49.         fr << "Parduotuveja Marytes 38-io dydzio batu nebuvo" << endl;
  50.     }
  51.  
  52.  
  53.  
  54.     fr.close();
  55.  
  56.     Spausdinti(CRfv, T, D, n);
  57.  
  58.  
  59.         return 0;
  60. }
  61.  
  62. void Skaityti(const char fv[], char A[], int B[], int & n)
  63. {
  64.     ifstream fd(fv);
  65.     fd >> n;
  66.     for (int i = 0; i < n; i++)
  67.     {
  68.         fd >> A[i] >> B[i];
  69.     }
  70.     fd.close();
  71. }
  72.  
  73. void Spausdinti(const char fv[], char A[], int B[], int n)
  74. {
  75.     ofstream fr(fv, ios::app);
  76.  
  77.     fr << " Batu sarasas " << endl;
  78.     fr << "--------------" << endl;
  79.     fr << " Tipas  Dydis " << endl;
  80.     fr << "--------------" << endl;
  81.  
  82.     for (int i = 0; i < n; i++)
  83.     {
  84.         fr << setw(4) << A[i] << "     " << setw(2) << B[i] << endl;
  85.     }
  86.     fr << "-------------" << endl;
  87.     fr.close();
  88.  
  89. }
  90.  
  91. int IeskotiBatu(char A[], int B[], int n, char tp, int dd)
  92. {
  93.     int ind = -1;
  94.     for (int i = 0; i < n; i++)
  95.     {
  96.         if((A[i] == tp) && (B[i] == dd))
  97.         {
  98.             ind = i;
  99.         }
  100.  
  101.     }
  102.     return ind;
  103.  
  104. }
  105.  
  106. void SalintiBatus (char A[], int B[], int & n, int ind)
  107. {
  108.     for (int i = ind; i < n-1; i++)
  109.     {
  110.         A[i] = A[i+1];
  111.         B[i] = B[i+1];
  112.     }
  113.     n--;
  114. }