1037: The simplest computer

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.