10033 - Interpreter
Moderator: Board moderators
Re: 10033 - Interpreter
OK, I have solved the problem. Basically I have used the same methods and just rearranged the input handling/
I still can't find what's wrong with this solution.
I still can't find what's wrong with this solution.
Re: 10033 - Interpreter
hey every body here ... hope you help me here
I found the following input and output here and i have 3 questions:
input:
output:
the 3 questions:
1- the command (913) what is the value of R1???
>>> my sol: go to add in r3 that means 0 in zero there value 1 that is 1 BUT R1 must to be zero to stop at the next line so that output will be 10
2- what i must to do when 000 and I must to increase the output++ or not ?
>>>> my sol: do not do any thing and do not increase the output
3- there is no 100, I must to halt after input finish but i must to increase the out put for halt or just when if there is 100 ?
i.e. what i must to do if there is no 100 ?
please hope you help me
I found the following input and output here and i have 3 questions:
input:
Code: Select all
221
422
425
000
311
712
712
913
031
Code: Select all
10
1- the command (913) what is the value of R1???
>>> my sol: go to add in r3 that means 0 in zero there value 1 that is 1 BUT R1 must to be zero to stop at the next line so that output will be 10
2- what i must to do when 000 and I must to increase the output++ or not ?
>>>> my sol: do not do any thing and do not increase the output
3- there is no 100, I must to halt after input finish but i must to increase the out put for halt or just when if there is 100 ?
i.e. what i must to do if there is no 100 ?
please hope you help me
Re: 10033 - Interpreter
hey i knowed the answer for the question 1 ,2,3
case 9 will generate 100 in the input
100 always will be there if not will generated
000 make the output++ ... dont do any comand
the inputs here give me correct answer but when i subment it is give me WA WA WA ... i think some thing with getting the output not proceses
can somebody help me here
case 9 will generate 100 in the input
100 always will be there if not will generated
000 make the output++ ... dont do any comand
the inputs here give me correct answer but when i subment it is give me WA WA WA ... i think some thing with getting the output not proceses
can somebody help me here
Code: Select all
import java.util.Scanner;
import java.util.Vector;
/**
*
* @author bjaguar
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean init = true;
int r[];
Vector<Integer> ram;
int noc,inst=0;
String line;
noc = Integer.parseInt(sc.nextLine());
sc.nextLine();
while (noc !=0){
// prepare for the test case
ram = new Vector<Integer>();
r = new int[10];
//loop on each test case
line = sc.nextLine();
while (!line.equals("")){
ram.add(Integer.parseInt(line));
line = sc.nextLine();
}//loop on every test case
noc--;
inst = proces(r, ram);
System.out.println(inst);
if (noc != 0)
System.out.println();
}//loop on all cases
}//main
private static int proces(int r[], Vector<Integer> ram){
int add = 0;
int inst = 0;
boolean stop = false;
int number, cmd, num1, num2;
for (int i=0;i<ram.size() && !stop;i++){
number = ram.get(i);
cmd = number/100;
num1 = number%100/10;
num2 = number%10;
switch(cmd){
case 2:
r[num1] = num2;
inst++;
break;
case 3:
r[num1] = (r[num1]+num2)%1000;
inst++;
break;
case 4:
r[num1] = (r[num1]*num2)%1000;
inst++;
break;
case 5:
r[num1] = r[num2];
inst++;
break;
case 6:
r[num1] = (r[num1]+r[num2])%1000;
inst++;
break;
case 7:
r[num1] = (r[num1]*r[num2])%1000;
inst++;
break;
case 8:
add = r[num2];
r[num1] = ram.get(add);
inst++;
break;
case 9:
add = r[num2];
ram.remove(add);
ram.add(add, r[num1]);
inst++;
break;
case 1:
if (num1 == 0 && num2 == 0){
stop = true;
inst++;
}// comand to stop
break;
case 0:
if ( r[num2]!=0 && (num1 != 0 || num2 != 0)){
i = r[num1]-1;
}// comand to stop
inst++;
break;
}//switch on comand type
}//loop on all comands in the case
return inst;
}// proces each case
}//class
-
- New poster
- Posts: 10
- Joined: Sun Dec 20, 2009 12:01 am
Re: 10033 - Interpreter
You are right, but this is BS. Problem description doesn't state how many new lines should be at the end of the last input. So, they should accept all the reasonable options or state what the heck they want.ExUCI wrote:There is an extra end-of-line at the end of the output, that's all!!!....the empty lines are between cases
Remove your code after AC
I got 2 WA's from having: 2 new lines, and 0 new lines. AC with 1 new line.
![:roll:](./images/smilies/icon_rolleyes.gif)
-
- New poster
- Posts: 10
- Joined: Sun Dec 20, 2009 12:01 am
Re: 10033 - Interpreter
I've compiled the various inputs from this thread into one.
The output is EXACTLY as below
There is a SINGLE NEWLINE after 3007 and TWO NEWLINES between outputs.
This tests pretty much everything.
Code: Select all
5
299
492
495
399
492
495
399
283
279
689
078
100
000
000
000
221
422
425
000
311
712
712
913
031
299
233
255
990
803
301
050
100
212
415
521
721
532
439
543
631
339
923
029
873
674
027
023
299
492
495
399
492
495
399
589
279
689
279
078
100
000
000
000
Code: Select all
16
10
26
835
3007
This tests pretty much everything.
-
- New poster
- Posts: 5
- Joined: Mon Mar 14, 2011 4:59 am
Re: 10033 - Interpreter
Getting Runtime Error, also, I think my code has something wrong, because on the UVA example the output is 16, and Im getting 13 !
My code:
Looking forward for an answer !
Thanks !
My code:
Code: Select all
/*
* File: interpreter.cpp
* Author: Leonardo
*
* Created on 14 de Março de 2011, 02:56
*/
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;
int numIns = 0;
int reg[10];
int ram[1001];
void verifica(int ins, int valor) {
int temp, nums[2], pos;
temp = valor / 10;
nums[0] = temp;
temp *= 10;
valor -= temp;
nums[1] = valor;
switch (ins) {
case 0:
if(reg[nums[1]] != 0){
pos = reg[nums[0]];
numIns += reg[nums[1]];
}else{
numIns++;
}
break;
case 1:
numIns++;
break;
case 2:
reg[nums[0]] = nums[1];
numIns++;
break;
case 3:
reg[nums[0]] = (reg[nums[0]] + nums[1]) % 1000;
numIns++;
break;
case 4:
reg[nums[0]] = (reg[nums[0]] * nums[1]) % 1000;
numIns++;
break;
case 5:
reg[nums[0]] = reg[nums[1]];
numIns++;
break;
case 6:
reg[nums[0]] = (reg[nums[0]] + reg[nums[1]]) % 1000;
numIns++;
break;
case 7:
reg[nums[0]] = (reg[nums[0]] * reg[nums[1]]);
numIns++;
case 8:
reg[nums[0]] = ram[reg[nums[1]]];
numIns++;
break;
case 9:
ram[reg[nums[1]]] = reg[nums[0]];
numIns++;
break;
}
}
int main(int argc, char** argv) {
int entradas;
int modulo, instr;
cin >> entradas;
cout << endl;
for (int j = 0; j < entradas; j++) {
memset(reg, 0, sizeof (reg));
memset(ram, 0, sizeof (ram));
do {
cin >> ram[numIns];
modulo = ram[numIns] % 100;
instr = (ram[numIns] - modulo) / 100;
verifica(instr, modulo);
} while (instr != 1);
cout << endl << numIns << endl << endl;
}
return 0;
}
Thanks !
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10033 - Interpreter
1 There is one case below
RAM location, RAM value, description
000, 299, Set register 9 to 9 // R9=9
001, 492, Multiply register 9 by 2 // R9=18
002, 495, Multiply register 9 by 5 // R9=90
003, 399, Add 9 to register 9 // R9=99
004, 492, Multiply register 9 by 2 // R9=198
005, 495, Multiply register 9 by 5 // R9=990
006, 399, Add 9 to register 9 // R9=999
007, 283, Set register 8 to 3 // R8=3
008, 279, Set register 7 to 9 // R7=9
009, 689, Add register 9 value (R9=999) to register 8 // R8=2 (b/c mod 1000 happens)
010, 078, Go to location in register 7 (R7=9) unless R8==0 (R8=2)
009, 689, Add register 9 value (R9=999) to register 8 // R8=1 (b/c mod 1000 happens)
010, 078, Go to location in register 7 (R7=9) unless R8==0 (R8=1)
009, 689, Add register 9 value (R9=999) to register 8 // R8=0 (b/c mod 1000 happens)
010, 078, Go to location in register 7 unless R8==0 (R8=0)
011, 100, Halt
RAM location, RAM value, description
000, 299, Set register 9 to 9 // R9=9
001, 492, Multiply register 9 by 2 // R9=18
002, 495, Multiply register 9 by 5 // R9=90
003, 399, Add 9 to register 9 // R9=99
004, 492, Multiply register 9 by 2 // R9=198
005, 495, Multiply register 9 by 5 // R9=990
006, 399, Add 9 to register 9 // R9=999
007, 283, Set register 8 to 3 // R8=3
008, 279, Set register 7 to 9 // R7=9
009, 689, Add register 9 value (R9=999) to register 8 // R8=2 (b/c mod 1000 happens)
010, 078, Go to location in register 7 (R7=9) unless R8==0 (R8=2)
009, 689, Add register 9 value (R9=999) to register 8 // R8=1 (b/c mod 1000 happens)
010, 078, Go to location in register 7 (R7=9) unless R8==0 (R8=1)
009, 689, Add register 9 value (R9=999) to register 8 // R8=0 (b/c mod 1000 happens)
010, 078, Go to location in register 7 unless R8==0 (R8=0)
011, 100, Halt
Check input and AC output for thousands of problems on uDebug!
Re: 10033 - Interpreter
Thanks a bunch for this careful explanation. It's really appreciated. I worked this out again and it makes sense. I do have one question, though.brianfry713 wrote:1 There is one case below
I don't fully understand how it was clear to you to repeat only the line before the goto until the condition in the goto was met. In other words, how did you know that these couple lines were to be repeated?
Code: Select all
689 Add register 9 value to register 8
078 Go to location in register 7 unless R8==0
Re: 10033 - Interpreter
hey please can you explain where the "16" in the output came from ! ![:roll:](./images/smilies/icon_rolleyes.gif)
![:roll:](./images/smilies/icon_rolleyes.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10033 - Interpreter
vinit R7 = 9 so you go to that location.
fresher96, read my post in this thread two before yours: by brianfry713 » Sat Mar 01, 2014 7:22 am
fresher96, read my post in this thread two before yours: by brianfry713 » Sat Mar 01, 2014 7:22 am
Check input and AC output for thousands of problems on uDebug!
Re: 10033 - Interpreter
can anyone explain the fourth case of input .... that it's answer is 835I've compiled the various inputs from this thread into one
especially for 923 & 023 !
what does 9ds in general means "the value in RAM !!!"
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10033 - Interpreter
Code: Select all
1: RAM[0] = 212, set register 1 to 2
2: RAM[1] = 415, multiply register 1 = 2 by 5, now = 10
3: RAM[2] = 521, set register 2 to the value of register 1 = 10
4: RAM[3] = 721, multiply register 2 = 10 by the value of register 1 = 10, now = 100
5: RAM[4] = 532, set register 3 to the value of register 2 = 100
6: RAM[5] = 439, multiply register 3 = 100 by 9, now = 900
7: RAM[6] = 543, set register 4 to the value of register 3 = 900
8: RAM[7] = 631, add the value of register 1 = 10 to register 3 = 900, now = 910
9: RAM[8] = 339, add 9 to register 3 = 910, now = 919
10: RAM[9] = 923, set the value in RAM whose address is in register 3 = 919 to the value of register 2 = 100
11: RAM[10] = 29, goto the location in register 2 = 100 unless register 9 = 0 contains 0
12: RAM[11] = 873, set register 7 to the value in RAM whose address is in register 0 = 3, now 919
13: RAM[12] = 674, add the value of register 4 = 900 to register 7 = 100, now = 0
14: RAM[13] = 27, goto the location in register 2 = 100 unless register 7 = 0 contains 0
15: RAM[14] = 23, goto the location in register 2 = 100 unless register 3 = 919 contains 0
16-834: RAM[100-918] = 0, goto the location in register 0 = 0 unless register 0 = 0 contains 0
835: RAM[919] = 100, Halt
835
Check input and AC output for thousands of problems on uDebug!
Re: 10033 - Interpreter
thanks a lot MR.brianfry713 wrote:Code: Select all
1: RAM[0] = 212, set register 1 to 2 2: RAM[1] = 415, multiply register 1 = 2 by 5, now = 10 3: RAM[2] = 521, set register 2 to the value of register 1 = 10 4: RAM[3] = 721, multiply register 2 = 10 by the value of register 1 = 10, now = 100 5: RAM[4] = 532, set register 3 to the value of register 2 = 100 6: RAM[5] = 439, multiply register 3 = 100 by 9, now = 900 7: RAM[6] = 543, set register 4 to the value of register 3 = 900 8: RAM[7] = 631, add the value of register 1 = 10 to register 3 = 900, now = 910 9: RAM[8] = 339, add 9 to register 3 = 910, now = 919 10: RAM[9] = 923, set the value in RAM whose address is in register 3 = 919 to the value of register 2 = 100 11: RAM[10] = 29, goto the location in register 2 = 100 unless register 9 = 0 contains 0 12: RAM[11] = 873, set register 7 to the value in RAM whose address is in register 0 = 3, now 919 13: RAM[12] = 674, add the value of register 4 = 900 to register 7 = 100, now = 0 14: RAM[13] = 27, goto the location in register 2 = 100 unless register 7 = 0 contains 0 15: RAM[14] = 23, goto the location in register 2 = 100 unless register 3 = 919 contains 0 16-834: RAM[100-918] = 0, goto the location in register 0 = 0 unless register 0 = 0 contains 0 835: RAM[919] = 100, Halt 835
this was ambiguous for mebrianfry713
and thanks for the detailed description
Re: 10033 - Interpreter
Hi, there is my code
I tried this input
But Im getting this output
instead of
Any suggestions what can be wrong?
EDIT: AC
Code: Select all
else if (instruction == 9)
ram[ram[b]] = r[a]; // facepalm
Code: Select all
5
299
492
495
399
492
495
399
283
279
689
078
100
000
000
000
221
422
425
000
311
712
712
913
031
299
233
255
990
803
301
050
100
212
415
521
721
532
439
543
631
339
923
029
873
674
027
023
299
492
495
399
492
495
399
589
279
689
279
078
100
000
000
000
Code: Select all
16
10
26
636
3007
Code: Select all
16
10
26
835
3007
EDIT: AC