HDOJ 1283 最简单的计算机(水)

来源:互联网 发布:附近淘宝店 编辑:程序博客网 时间:2024/06/11 07:55

【思路】:水。

【AC代码】:

#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>#include <iomanip>using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */#define MAX 200+10int main(int argc, char** argv) {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);int m1 = 0, m2 = 0;while (cin >> m1 >> m2){int i = 0;int r1 = 0, r2 = 0, r3 = 0;char str[MAX];getchar();gets(str);for (i = 0; i < strlen(str); i++){switch(str[i]){case 'A':r1 = m1;break;case 'B':r2 = m2;break;case 'C':m1 = r3;break;case 'D':m2 = r3;break;case 'E':r3 = r1+r2;break;case 'F':r3 = r1-r2;break;} }cout << m1 << "," << m2 << endl;}return 0;}


0 0