1037: Simplest computer time limit: 1 Sec memory limit: MB
Submitted by: 187 resolution: 134
Submitted State [Discussion Version] The title describes a research organization called Pigheadthree designed an experimental computer named PPMM. PPMM can only perform a simple six command a,b,c,d,e,f, only two memory m1,m2, and three registers of R1,R2,R3. The six commands have the following meanings:
Command A: Load the memory M1 data into the register R1;
Command B: Load the memory M2 data into the register R2;
Command C: Load the data of the register R3 into the memory M1;
Command D: Load the data of the register R3 into the memory M2;
Command E: The data in the register R1 and the data in the register R2 are added, and the result is placed in the Register R3;
Command F: Subtracts the data in the register R1 from the data in the register R2, and the result is placed in the register R3.
Your task is to design a program to simulate the operation of PPMM. The input has several groups, each group has 2 rows, the first row is 2 integers, respectively, represents the initial content in M1 and M2, and the second line is a string of not more than 200 from the capital A to F consisting of a command string, the meaning of the command string as described above. Output corresponds to each set of inputs, output only one row, two integers, respectively, representing the contents of m1,m2, where M1 and M2 are separated by commas. Sample input
321456ABECAEDBECAF 288abeced876356
Sample output
388,3882717080,1519268
Hint Source
#include <iostream>
using namespace Std;
int main () {
int I,M1,M2,R1,R2,R3;
String str;
while (CIN>>M1>>M2) {
r1=0;
r2=0;
r3=0;
cin>>str;
for (i=0;str[i]!= ' n '; i++) {
if (str[i]== ' A ') r1=m1;
else if (str[i]== ' B ') r2=m2;
else if (str[i]== ' C ') m1=r3;
else if (str[i]== ' D ') m2=r3;
else if (str[i]== ' E ') r3=r1+r2;
else if (str[i]== ' F ') r3=r1-r2;
}
cout<<m1<< "," <<m2<<endl;
}
return 0;
}
1037: The simplest computer