Advertisement
Mihai_Preda

Untitled

Feb 18th, 2021
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. ifstream in("valutar.in");
  6. ofstream out("valutar.out");
  7. char cod[10001];
  8. int juc[101],leu[101],euro[101],pas[101],leucasa[10001],eurocasa[10001];
  9. int main()
  10. {
  11.     int cer,a,b,nr,n,m,l,e,x,ujuc,urmatorul,poz[101],k;
  12.     in>>cer>>a>>b>>nr>>n>>m>>l>>e>>x;
  13.     for(int i=1; i<=m; i++)
  14.     {
  15.         leu[i]=l;
  16.         euro[i]=e;
  17.         poz[i]=1;
  18.     }
  19.     ujuc=m;
  20.     for(int i=1; i<=n; i++)
  21.     {
  22.         in>>cod[i]>>leucasa[i]>>eurocasa[i];
  23.     }
  24.     for(int i=1; i<=x; i++)
  25.     {
  26.         k=1;
  27.         int ok = 1;
  28.         while(juc[(ujuc-1+k)%m+1]==1)
  29.         {
  30.             k++;
  31.             if(k == m)
  32.             {
  33.                 ok = 0;
  34.                 break;
  35.             }
  36.         }
  37.         if(ok == 0)
  38.             break;
  39.         urmatorul=(ujuc+k)%m;
  40.         if(urmatorul==0)
  41.         {
  42.             urmatorul=m;
  43.         }
  44.         nr=(a*nr+b)%n+1;
  45.         poz[urmatorul]=(poz[urmatorul]-1+nr)%n+1;
  46.         if(cod[poz[urmatorul]]=='G')
  47.         {
  48.             if(leu[urmatorul]>=poz[urmatorul]*leucasa[poz[urmatorul]])
  49.             {
  50.                 leu[urmatorul]=leu[urmatorul]-poz[urmatorul]*leucasa[poz[urmatorul]];
  51.             }
  52.             else if(pas[urmatorul]>=1)
  53.             {
  54.                 pas[urmatorul]--;
  55.             }
  56.             else
  57.             {
  58.                 juc[urmatorul]=1;
  59.             }
  60.         }
  61.         else if(cod[poz[urmatorul]]=='R')
  62.         {
  63.             pas[urmatorul]++;
  64.  
  65.         }
  66.         else if(cod[poz[urmatorul]]=='V')
  67.         {
  68.             if(euro[urmatorul]>=poz[urmatorul]*eurocasa[poz[urmatorul]])
  69.             {
  70.                 euro[urmatorul]=euro[urmatorul]-poz[urmatorul]*eurocasa[poz[urmatorul]];
  71.             }
  72.             else if(pas[urmatorul]>=1)
  73.             {
  74.                 pas[urmatorul]--;
  75.             }
  76.             else
  77.             {
  78.                 juc[urmatorul]=1;
  79.             }
  80.         }
  81.         ujuc=urmatorul;
  82.     }
  83.     int nrjucfinal=0;
  84.     if(cer==1)
  85.     {
  86.         for(int i=1; i<=m; i++)
  87.         {
  88.             if(juc[i]!=1)
  89.             {
  90.                 nrjucfinal++;
  91.             }
  92.         }
  93.         out<<nrjucfinal;
  94.     }
  95.     int maxeuro=0,jucfin;
  96.     if(cer==2)
  97.     {
  98.         for(int i=1; i<=m; i++)
  99.         {
  100.             if(juc[i]!=1 && euro[i]>maxeuro)
  101.             {
  102.                 maxeuro=euro[i];
  103.                 jucfin=i;
  104.  
  105.             }
  106.         }
  107.         out<<jucfin;
  108.     }
  109.     return 0;
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement