Advertisement
Guest User

festyn

a guest
Jan 22nd, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     fstream plik;
  8.     plik.open("festyn.txt");
  9.     int n,m;
  10.     int a[1000];
  11.     int c[1000];
  12.     int t[1000];
  13.     int b[1000];
  14.     int nr =1;
  15.     string jd ="jd";
  16.     while(!plik.eof())
  17.     {
  18.         plik>>n;
  19.         int maxi = 0;
  20.         int pkt = 0;
  21.         for(int i = 0; i<n; i++)
  22.         {
  23.             plik>>a[i]>>b[i];
  24.             c[i]=a[i]+b[i]-1;
  25.         }
  26.         plik>>m;
  27.         for(int i = 0; i<m; i++)
  28.         {
  29.             plik>>t[i];
  30.             for(int j = 0; j<n; j++)
  31.             {
  32.                 if(t[i]>=a[j] && t[i]<=c[j])
  33.                 {
  34.                     pkt++;
  35.                     if(t[i]-a[j]+1 > maxi)
  36.                     {
  37.                         maxi = t[i]-a[j]+1;
  38.                     }
  39.                     a[j]=0;
  40.                     b[j]=0;
  41.                     c[j]=0;
  42.                 }
  43.             }
  44.         }
  45.         for(int i = 0; i<n; i++)
  46.         {
  47.                 if(maxi < b[i])
  48.                 {
  49.                     maxi = b[i];
  50.                 }
  51.         }
  52.         cout<<"Zestaw nr "<<nr<<" - liczba punktow: "<<pkt<<endl;
  53.         cout<<"Zestaw nr "<<nr<<" - maksymalny czas widocznosci tarczy: "<<maxi<<endl;
  54.         nr++;
  55.     }
  56.     plik.close();
  57.     plik.open("festyn.txt");
  58.     int nrr = 1;
  59.     int maxi = 0;
  60.     while(!plik.eof())
  61.     {
  62.         int max_pkt = 0;
  63.         int sekunda;
  64.         int pkt = 0;
  65.         plik>>n;
  66.         for(int i = 0; i<n; i++)
  67.         {
  68.             plik>>a[i]>>b[i];
  69.             c[i]=a[i]+b[i]-1;
  70.         }
  71.         plik>>m;
  72.         for(int i = 0; i<m; i++)
  73.         {
  74.             plik>>t[i];
  75.         }
  76.         for(int i = 0; i<m; i++)
  77.         {
  78.             for(int j = 0; j<n; j++)
  79.             {
  80.                 if(t[i]>=a[j] && t[i]<=c[j])
  81.                 {
  82.                     pkt++;
  83.                     if(t[i]-a[j]+1 > maxi)
  84.                     {
  85.                         maxi = t[i]-a[j]+1;
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.         for(int i = 1; i<301; i++)
  91.         {
  92.             int pkt_tmp = 0;
  93.             for(int j = 0; j<n; j++)
  94.             {
  95.                 if(i>=a[j] && i<=c[j])
  96.                     pkt_tmp++;
  97.             }
  98.             if(pkt_tmp > max_pkt)
  99.             {
  100.                 max_pkt = pkt_tmp;
  101.                 sekunda = i;
  102.             }
  103.         }
  104.         cout<<"Zestaw nr "<<nrr<<" - sekunda w ktorej powinnien pasc strzal: "<<sekunda<<endl;
  105.         cout<<"Zestaw nr "<<nrr<<" - liczba punktow wedlug nowych zasad: "<<pkt<<endl;
  106.         nrr++;
  107.     }
  108.     return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement