10033 - Interpreter
Moderator: Board moderators
Yes, I got accepted and I hardly doubt that cases like this one would be in the judge's input, unless it's the last case, because of the lines that you have to ignore.
Try to recode your program, you might have done some mistakes, and don't forget that all results are mod 1000!
Try to recode your program, you might have done some mistakes, and don't forget that all results are mod 1000!
Thiago Sonego Goulart - UFMG/Brazil
10033
here is my code
how can i solve the problem of time limit
#include<stdio.h>
int s,i,j;
int RAM[20][3],REG[10],ans;
char save[6];
main(){
scanf("%d\n",&s);
j=0;
for(i=0;i<s;i++){
j=0;
while(gets(save)){
if(!save[0])break;
if(save[0]=='0'&& save[1]=='0' &&save[2]=='0')
break;
RAM[j][0]=save[0]-'0';
RAM[j][1]=save[1]-'0';
RAM[j][2]=save[2]-'0';
j++;
}
for(;j<20;j++){
RAM[j][0]=0;
RAM[j][1]=0;
RAM[j][2]=0;
}
for(ans=0,j=0;;){
if(RAM[j][0]==1)
{
ans++;
break;
}
else if(RAM[j][0]==2)
{
REG[ RAM[j][1] ] = RAM[j][2];
}
else if(RAM[j][0]==3)
{
REG[ RAM[j][1] ] += RAM[j][2];
REG[ RAM[j][1] ]%=1000;
}
else if(RAM[j][0]==4)
{
REG[ RAM[j][1] ] *= RAM[j][2];
REG[ RAM[j][1] ]%=1000;
}
else if(RAM[j][0]==5)
{
REG[ RAM[j][1] ] = REG[ RAM[j][2] ];
}
else if(RAM[0]==6)
{
REG[ RAM[j][1] ] += REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
}
else if(RAM[j][0]==7)
{
REG[ RAM[j][1] ] *= REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
}
else if(RAM[j][0]==8)
{
REG[ RAM[j][1] ] = RAM[j][ REG[ RAM[j][2] ] ];
}
else if(RAM[j][0]==9)
{
RAM[j][ REG[ RAM[j][2] ] ] = REG[ RAM[j][1] ];
}
else if(RAM[j][0]==0 && REG[ RAM[j][2] ]!=0)
{
j = REG[ RAM[j][1] ];
}
ans++;
j++;
}
printf("%d\n",ans);
if(i!=s-1){
printf("\n");
}
}
}
how can i solve the problem of time limit
#include<stdio.h>
int s,i,j;
int RAM[20][3],REG[10],ans;
char save[6];
main(){
scanf("%d\n",&s);
j=0;
for(i=0;i<s;i++){
j=0;
while(gets(save)){
if(!save[0])break;
if(save[0]=='0'&& save[1]=='0' &&save[2]=='0')
break;
RAM[j][0]=save[0]-'0';
RAM[j][1]=save[1]-'0';
RAM[j][2]=save[2]-'0';
j++;
}
for(;j<20;j++){
RAM[j][0]=0;
RAM[j][1]=0;
RAM[j][2]=0;
}
for(ans=0,j=0;;){
if(RAM[j][0]==1)
{
ans++;
break;
}
else if(RAM[j][0]==2)
{
REG[ RAM[j][1] ] = RAM[j][2];
}
else if(RAM[j][0]==3)
{
REG[ RAM[j][1] ] += RAM[j][2];
REG[ RAM[j][1] ]%=1000;
}
else if(RAM[j][0]==4)
{
REG[ RAM[j][1] ] *= RAM[j][2];
REG[ RAM[j][1] ]%=1000;
}
else if(RAM[j][0]==5)
{
REG[ RAM[j][1] ] = REG[ RAM[j][2] ];
}
else if(RAM[0]==6)
{
REG[ RAM[j][1] ] += REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
}
else if(RAM[j][0]==7)
{
REG[ RAM[j][1] ] *= REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
}
else if(RAM[j][0]==8)
{
REG[ RAM[j][1] ] = RAM[j][ REG[ RAM[j][2] ] ];
}
else if(RAM[j][0]==9)
{
RAM[j][ REG[ RAM[j][2] ] ] = REG[ RAM[j][1] ];
}
else if(RAM[j][0]==0 && REG[ RAM[j][2] ]!=0)
{
j = REG[ RAM[j][1] ];
}
ans++;
j++;
}
printf("%d\n",ans);
if(i!=s-1){
printf("\n");
}
}
}
i do some change , but it isn't work .
can some one let me know where is the plb.
thx a lot .
#include<stdio.h>
int s,i,j,k;
int RAM[1000][3],REG[10]={0},ans;
char save[6];
main(int argc,char *argv[]){
/*FILE *fp;
fp=fopen(argv[1],"r");*/
fscanf(stdin,"%d\n",&s);
/*printf("%d\n",s);*/
j=0;
for(i=0;i<s;i++){
j=0;
while(fgets(save,6,stdin)!=NULL){
if(save[0]=='\n')
{
break;
}
else
{
RAM[j][0]=save[0]-'0';
RAM[j][1]=save[1]-'0';
RAM[j][2]=save[2]-'0';
j++;
}
}
for(k=j;k<1000;k++){
RAM[k][0]=0;
RAM[k][1]=0;
RAM[k][2]=0;
}
/*for(k=0;k<j;k++){
printf("%d %d %d %d\n",i,RAM[k][0],RAM[k][1],RAM[k][2]);
}
printf("\n==\n");*/
for(k=0;k<10;k++){
REG[k]=0;
}
ans=0;
for(j=0;;){
if(RAM[j][0]==1)
{
ans++;
break;
}
else if(RAM[j][0]==2)
{
REG[ RAM[j][1] ] = RAM[j][2];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==3)
{
REG[ RAM[j][1] ] += RAM[j][2];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==4)
{
REG[ RAM[j][1] ] *= RAM[j][2];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==5)
{
REG[ RAM[j][1] ] = REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==6)
{
REG[ RAM[j][1] ] += REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==7)
{
REG[ RAM[j][1] ] *= REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==8)
{
REG[ RAM[j][1] ] = RAM[j][ REG[ RAM[j][2] ] ];
j++;
}
else if(RAM[j][0]==9)
{
RAM[j][ REG[ RAM[j][2] ] ] = REG[ RAM[j][1] ];
j++;
}
else if(RAM[j][0]==0)
{
if(REG[ RAM[j][2] ]!=0)
{
j = REG[ RAM[j][1] ];
}
else
{
j++;
}
}
if(j==1000){
j=0;
}
ans++;
}
printf("%d\n",ans);
if(i!=s-1){
printf("\n");
}
}
}
can some one let me know where is the plb.
thx a lot .
#include<stdio.h>
int s,i,j,k;
int RAM[1000][3],REG[10]={0},ans;
char save[6];
main(int argc,char *argv[]){
/*FILE *fp;
fp=fopen(argv[1],"r");*/
fscanf(stdin,"%d\n",&s);
/*printf("%d\n",s);*/
j=0;
for(i=0;i<s;i++){
j=0;
while(fgets(save,6,stdin)!=NULL){
if(save[0]=='\n')
{
break;
}
else
{
RAM[j][0]=save[0]-'0';
RAM[j][1]=save[1]-'0';
RAM[j][2]=save[2]-'0';
j++;
}
}
for(k=j;k<1000;k++){
RAM[k][0]=0;
RAM[k][1]=0;
RAM[k][2]=0;
}
/*for(k=0;k<j;k++){
printf("%d %d %d %d\n",i,RAM[k][0],RAM[k][1],RAM[k][2]);
}
printf("\n==\n");*/
for(k=0;k<10;k++){
REG[k]=0;
}
ans=0;
for(j=0;;){
if(RAM[j][0]==1)
{
ans++;
break;
}
else if(RAM[j][0]==2)
{
REG[ RAM[j][1] ] = RAM[j][2];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==3)
{
REG[ RAM[j][1] ] += RAM[j][2];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==4)
{
REG[ RAM[j][1] ] *= RAM[j][2];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==5)
{
REG[ RAM[j][1] ] = REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==6)
{
REG[ RAM[j][1] ] += REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==7)
{
REG[ RAM[j][1] ] *= REG[ RAM[j][2] ];
REG[ RAM[j][1] ]%=1000;
j++;
}
else if(RAM[j][0]==8)
{
REG[ RAM[j][1] ] = RAM[j][ REG[ RAM[j][2] ] ];
j++;
}
else if(RAM[j][0]==9)
{
RAM[j][ REG[ RAM[j][2] ] ] = REG[ RAM[j][1] ];
j++;
}
else if(RAM[j][0]==0)
{
if(REG[ RAM[j][2] ]!=0)
{
j = REG[ RAM[j][1] ];
}
else
{
j++;
}
}
if(j==1000){
j=0;
}
ans++;
}
printf("%d\n",ans);
if(i!=s-1){
printf("\n");
}
}
}
Don't create a new thread if there is one already..
Use old threads..
http://online-judge.uva.es/board/viewtopic.php?t=13985
http://online-judge.uva.es/board/viewtopic.php?t=9667
http://online-judge.uva.es/board/viewtopic.php?t=940
http://online-judge.uva.es/board/viewtopic.php?t=8923
and so on..
Use old threads..
http://online-judge.uva.es/board/viewtopic.php?t=13985
http://online-judge.uva.es/board/viewtopic.php?t=9667
http://online-judge.uva.es/board/viewtopic.php?t=940
http://online-judge.uva.es/board/viewtopic.php?t=8923
and so on..
Help me! Input code?
Help me! Input Code?
Input:
Input:
Code: Select all
2
299
492
495
399
492
495
399
283
279
689
078
100
000
000
000
456
789
234
453
125
175
183
256
012
100
000
Re: 10033 - Interpreter - I need a multi-testcase input
![:cry:](./images/smilies/icon_cry.gif)
help me,please!
Why does your program stop when 125 is reached tgoulart? Isn't 100 mean to be the halt instruction? I'm confused. Thanks for your time!tgoulart wrote:Actually, my program stops when 125 is reached. It is the halt instruction, so the program finishes there, and the subsequent lines should be ignored. This way we have 5 instructions executed, including the 125.
My program stops because I verify the instruction by the first digit, and 1 is the halt operation. But if you take a look at the table, you will see that 125 isn't a valid instruction.hardcode wrote:Why does your program stop when 125 is reached tgoulart? Isn't 100 mean to be the halt instruction? I'm confused. Thanks for your time!tgoulart wrote:Actually, my program stops when 125 is reached. It is the halt instruction, so the program finishes there, and the subsequent lines should be ignored. This way we have 5 instructions executed, including the 125.
Thiago Sonego Goulart - UFMG/Brazil