# 最简单的计算机

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7774    Accepted Submission(s): 4379

Problem Description

命令A：将内存M1的数据装到寄存器R1中；
命令B：将内存M2的数据装到寄存器R2中；
命令C：将寄存器R3的数据装到内存M1中；
命令D：将寄存器R3的数据装到内存M2中；
命令E：将寄存器R1中的数据和寄存器R2中的数据相加，结果放到寄存器R3中；
命令F：将寄存器R1中的数据和寄存器R2中的数据相减，结果放到寄存器R3中。

Input

Output

Sample Input
100 288 ABECED 876356 321456 ABECAEDBECAF

Sample Output
388,388 2717080,1519268

Author
SmallBeer(CML)

Source

AC的C语言程序如下：

/* HDU1283 最简单的计算机 */

#include <stdio.h>

#define N 200

char command[N+1];

int main(void)
{
int m1, m2, r1, r2, r3;

while(scanf("%d%d", &m1, &m2) != EOF) {
scanf("%s", command);

r1 = r2 = r3 = 0;

int i = 0;
while(command[i]) {
if(command[i] == 'A')
r1 = m1;
else if(command[i] == 'B')
r2 = m2;
else if(command[i] == 'C')
m1 = r3;
else if(command[i] == 'D')
m2 = r3;
else if(command[i] == 'E')
r3 = r1 + r2;
else if(command[i] == 'F')
r3 = r1 - r2;

i++;
}

printf("%d,%d\n", m1, m2);
}

return 0;
}

AC的C++语言程序如下：

/* HDU1283 最简单的计算机 */

#include <iostream>

using namespace std;

int main()
{
int m1, m2, r1, r2, r3;
string command;

while(cin >> m1 >> m2) {
cin >> command;

r1 = r2 = r3 = 0;

int i = 0;
while(command[i]) {
if(command[i] == 'A')
r1 = m1;
else if(command[i] == 'B')
r2 = m2;
else if(command[i] == 'C')
m1 = r3;
else if(command[i] == 'D')
m2 = r3;
else if(command[i] == 'E')
r3 = r1 + r2;
else if(command[i] == 'F')
r3 = r1 - r2;

i++;
}

cout << m1 << "," << m2 << endl;
}

return 0;
}