Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- ifstream in("valutar.in");
- ofstream out("valutar.out");
- char cod[10001];
- int juc[101],leu[101],euro[101],pas[101],leucasa[10001],eurocasa[10001];
- int main()
- {
- int cer,a,b,nr,n,m,l,e,x,ujuc,urmatorul,poz[101],k;
- in>>cer>>a>>b>>nr>>n>>m>>l>>e>>x;
- for(int i=1; i<=m; i++)
- {
- leu[i]=l;
- euro[i]=e;
- poz[i]=1;
- }
- ujuc=m;
- for(int i=1; i<=n; i++)
- {
- in>>cod[i]>>leucasa[i]>>eurocasa[i];
- }
- for(int i=1; i<=x; i++)
- {
- k=1;
- int ok = 1;
- while(juc[(ujuc-1+k)%m+1]==1)
- {
- k++;
- if(k == m)
- {
- ok = 0;
- break;
- }
- }
- if(ok == 0)
- break;
- urmatorul=(ujuc+k)%m;
- if(urmatorul==0)
- {
- urmatorul=m;
- }
- nr=(a*nr+b)%n+1;
- poz[urmatorul]=(poz[urmatorul]-1+nr)%n+1;
- if(cod[poz[urmatorul]]=='G')
- {
- if(leu[urmatorul]>=poz[urmatorul]*leucasa[poz[urmatorul]])
- {
- leu[urmatorul]=leu[urmatorul]-poz[urmatorul]*leucasa[poz[urmatorul]];
- }
- else if(pas[urmatorul]>=1)
- {
- pas[urmatorul]--;
- }
- else
- {
- juc[urmatorul]=1;
- }
- }
- else if(cod[poz[urmatorul]]=='R')
- {
- pas[urmatorul]++;
- }
- else if(cod[poz[urmatorul]]=='V')
- {
- if(euro[urmatorul]>=poz[urmatorul]*eurocasa[poz[urmatorul]])
- {
- euro[urmatorul]=euro[urmatorul]-poz[urmatorul]*eurocasa[poz[urmatorul]];
- }
- else if(pas[urmatorul]>=1)
- {
- pas[urmatorul]--;
- }
- else
- {
- juc[urmatorul]=1;
- }
- }
- ujuc=urmatorul;
- }
- int nrjucfinal=0;
- if(cer==1)
- {
- for(int i=1; i<=m; i++)
- {
- if(juc[i]!=1)
- {
- nrjucfinal++;
- }
- }
- out<<nrjucfinal;
- }
- int maxeuro=0,jucfin;
- if(cer==2)
- {
- for(int i=1; i<=m; i++)
- {
- if(juc[i]!=1 && euro[i]>maxeuro)
- {
- maxeuro=euro[i];
- jucfin=i;
- }
- }
- out<<jucfin;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement