123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
#include <iostream> #include <string> #include <sstream> using namespace std; int reg[10], ram[1000]; inline void decode(int ins, int &ir) { int opcode=ins/100; int op1=(ins%100)/10; int op2=ins%10; switch(opcode) { case 0: ir=(reg[op2]!=0 ? reg[op1]-1 : ir); break; case 1: ir=-2; break; case 2: reg[op1]=op2; break; case 3: reg[op1]+=op2; reg[op1]%=1000; break; case 4: reg[op1]*=op2; reg[op1]%=1000; break; case 5: reg[op1]=reg[op2]; break; case 6: reg[op1]+=reg[op2]; reg[op1]%=1000; break; case 7: reg[op1]*=reg[op2]; reg[op1]%=1000; break; case 8: reg[op1]=ram[reg[op2]]; break; case 9: ram[reg[op2]]=reg[op1]; break; default: break; } } int main() { int n; string s; cin>>n; getline(cin,s); getline(cin,s); for(int j=0; j<n; ++j) { int count=0, ir=0; for(int i=0; i<10; ++i) reg[i]=0; for(int i=0; i<1000; ++i) ram[i]=0; for(int i=0; i<1000;++i) { getline(cin,s); if(s=="") break; istringstream iss(s); iss>>ram[i]; } while(ir>=0) { decode(ram[ir], ir); ++ir; ++count; } if(j>0) cout<<'\n'; cout<<count<<'\n'; } }
12
for ( int i=0; i<1000; ++i ) ram[i]=0; std::fill( ram, ram+1000, 0 );