CSU 1267:operation (analog AH)

Source: Internet
Author: User

Title Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1267


Description

There are now -variables, respectively, with aa~zindicate that their initial values are0. Then there areNOperations , these operations are divided into the following6class:

(1) mov A, B:the variablebvalue is assigned to thea, equivalent toA = b, wherea,brefers to two variables.

(2) mov a,10:will beTenassigned toa, equivalent toA = ten, wherearefers to a variable,Tento refer to something less than -a positive integer.

(3) Add a, B:CalculationA + bvalue and assigns it to the variablea, equivalent toA = a + b, wherea,bRefer to some two variables.

(4) Sub a B:Calculationa–bvalue and assigns it to the variablea, equivalent toA = A–b, wherea,bRefer to some two variables.

(5) Add a,10:CalculationA + tenvalue and assigns it to the variablea, equivalent toA = a + ten, wherearefers to a variable,Tento refer to something less than -a positive integer.

(6) Sub a,10:Calculationa–10value and assigns it to the variablea, equivalent toA = a–10, wherearefers to a variable,Tento refer to something less than -a positive integer.

(7) print a:   a a

you need to do this in turn N operation, and when encountering the first (7) class operation, the value of the variable is output as required.

Input

The first line of the input data contains an integer n (1 <= N <= 10^5) N operations.

Then there are N row, each row contains a shape as described above.

Output

(7) class operation, output an integer in one line representing the value of the variable.

The data guarantees that the value of each variable is not exceeded during the operation 10^9 .

Sample Input
10print cadd C,10mov a,cadd a,aprint asub a,5sub b,aprint bsub c,bprint C
Sample Output
020-1525
HINT

Source

Seventh session of university student Program design Competition-warm-up


The code is as follows:

#include <cstdio> #include <cmath> #include <cstring> #include <algorithm>using namespace std;#    Include <iostream> #include <string>string ss;int main () {int n;    int f[27];    Char s[10];        while (~SCANF ("%d", &n)) {memset (f,0,sizeof (f));        Memset (s,0,sizeof (s));        Char A, B;            for (int i = 0; i < n; i++) {cin>>ss;                if (ss = = "Print") {cin>>a;            printf ("%d\n", f[a-' a ']);                } else if (ss = = "mov") {cin>>a>>b>>s;                    if (s[0]>= ' 0 ' && s[0] <= ' 9 ') {int num = 0;                    int len = strlen (s);                    for (int j = 0; J < Len; J + +) {num = num*10+s[j]-' 0 ';                } f[a-' a '] = num;                  } else  F[a-' a '] = f[s[0]-' a '];                } else if (ss = = "Add") {cin>>a>>b>>s;                    if (s[0]>= ' 0 ' && s[0] <= ' 9 ') {int num = 0;                    int len = strlen (s);                    for (int j = 0; J < Len; J + +) {num = num*10+s[j]-' 0 ';                } f[a-' a '] + = num;            } else f[a-' a '] + = f[s[0]-' a '];                } else if (ss = = "Sub") {cin>>a>>b>>s;                    if (s[0]>= ' 0 ' && s[0] <= ' 9 ') {int num = 0;                    int len = strlen (s);                    for (int j = 0; J < Len; J + +) {num = num*10+s[j]-' 0 ';                } f[a-' a ']-= num;   } else                 F[a-' a ']-= f[s[0]-' a ']; }}} return 0;}


CSU 1267:operation (analog AH)

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.