Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.40 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("test.in");
  4. ofstream fout("test.out");
  5. long long n,k=-1,nr,i,a,b;
  6. char c;
  7. long long v[100000];
  8. deque<int> outputs,inputs;
  9. long long vect[100000];
  10. string s[100000];
  11. int fr[20];
  12. long long *param[10];
  13. long long baza,paddle,ball,maxx;
  14. long long nrday13;
  15. map< pair<long long,long long>,long long> block;
  16. long long solve(string s,long long poz)
  17. {
  18.     long long l=s.size()-1;
  19.     long long cod;
  20.     if(s.size()>=2) cod=s[l]-'0'+(s[l-1]-'0')*10;
  21.     else  cod=s[0]-'0';
  22.     for(int i=0; i<=10; i++)
  23.         fr[i]=0;
  24.     l-=2;
  25.     long long parametrii=0;
  26.     while(l>=0)
  27.     {
  28.         fr[++parametrii]=s[l]-'0';
  29.         l--;
  30.     }
  31.     for(long long index=1; index<=4; index++)
  32.     {
  33.         if(fr[index]==0)
  34.         {
  35.             param[index]=&v[v[poz+index]];
  36.         }
  37.         else if(fr[index]==1)
  38.         {
  39.             param[index]=&v[poz+index];
  40.         }
  41.         else
  42.         {
  43.             param[index]=&v[v[poz+index]+baza];
  44.         }
  45.     }
  46.     if(cod==99)
  47.     {
  48.         //cout<<"finish";
  49.         return -1;
  50.     }
  51.     if(cod==1)
  52.     {
  53.         *param[3]=*param[1]+*param[2];
  54.         i+=4;
  55.     }
  56.     else if(cod==2)
  57.     {
  58.         *param[3]=*param[1]* *param[2];
  59.         i+=4;
  60.     }
  61.     else if(cod==3)
  62.     {
  63.         if(inputs.size()==0)
  64.             return -100;
  65.         *param[1]=inputs.front();
  66.         inputs.pop_front();
  67.         i+=2;
  68.     }
  69.     else if(cod==4)
  70.     {
  71.         outputs.push_back(*param[1]);
  72.         i+=2;
  73.     }
  74.     else if(cod==5)
  75.     {
  76.         if(*param[1]==0)
  77.         {
  78.             i+=3;
  79.         }
  80.         else
  81.             i=*param[2];
  82.     }
  83.     else if(cod==6)
  84.     {
  85.         if(*param[1]!=0)
  86.         {
  87.             i+=3;
  88.         }
  89.         else
  90.             i=*param[2];
  91.     }
  92.     else if(cod==7)
  93.     {
  94.         if(*param[1]<*param[2])
  95.         {
  96.             *param[3]=1;
  97.         }
  98.         else *param[3]=0;
  99.         i+=4;
  100.     }
  101.     else if(cod==8)
  102.     {
  103.         if(*param[1]==*param[2])
  104.         {
  105.             *param[3]=1;
  106.         }
  107.         else *param[3]=0;
  108.         i+=4;
  109.     }
  110.     else if(cod==9)
  111.     {
  112.         baza+=*param[1];
  113.         i+=2;
  114.     }
  115.     return 0;
  116. }
  117. int main()
  118. {
  119.     long long semn=1;
  120.     inputs.push_back(0);
  121.     while(fin>>c)
  122.     {
  123.         if(c==',')
  124.         {
  125.             v[++k]=nr*semn;
  126.             semn=1;
  127.             nr=0;
  128.         }
  129.         else if(c>='0'&&c<='9')
  130.         {
  131.             s[k+1]+=c;
  132.             nr*=10LL;
  133.             nr+=c-'0';
  134.         }
  135.         else if(c=='-')
  136.         {
  137.             semn=-1;
  138.         }
  139.     }
  140.     v[++k]=nr;
  141.     for(i=0; i<=k;)
  142.     {
  143.         while(solve(s[i],i)>=0);
  144.         long long x,y,id;
  145.         while(outputs.size()!=0)
  146.         {
  147.             x=outputs.front();
  148.                 outputs.pop_front();
  149.             y=outputs.front();
  150.                 outputs.pop_front();
  151.             id=outputs.front();
  152.                 outputs.pop_front();
  153.             if(id==3)
  154.             {
  155.                 paddle=x;
  156.             }
  157.             else if(id==4)
  158.             {
  159.                 ball=x;
  160.             }
  161.             if (x == -1 && y == 0){
  162.                 cout << id << '\n';
  163.             maxx=max(id,maxx);
  164.             }
  165.         }
  166.         if(paddle<ball)
  167.             inputs.push_back(1);
  168.         else if(paddle>ball)
  169.             inputs.push_back(-1);
  170.         else inputs.push_back(0);
  171.     }
  172.  
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement