#include <stdio.h>#include<string.h>intMain () {intN,i; Chara[ $]; intf=0, l=0; Gets (a); for(i=0; I<strlen (a); i++) { if(a[i]>='0'&&a[i]<='9')//if it's a number { if(a[i+1]>='0'&&a[i+1]<='9')//If the back is a number ,{f= (f+a[i]- -)*Ten;//into a number forward into a } Else//Otherwise, it is a space, what is stored directly as a number{f=f+a[i]- -; Break; } } } for(I=strlen (a);i>0; i--)//second two-digit number { if(a[i]>='0'&&a[i]<='9')//if it's a number { if(a[i-1]>='0'&&a[i-1]<='9')//If the front one is a number ,{L=l+a[i]- -; } Else//Otherwise, it is a space, what is stored directly as a number{L=l+ (a[i]- -)*Ten;//into a number forward into a Break; } /*35+14*/ } } for(i=0; I<strlen (a); i++) { if(a[i]=='+') printf ("%d\n", f+l); Else if(a[i]=='-') printf ("%d\n", F-l); Else if(a[i]=='*') printf ("%d\n", f*l); Else if(a[i]=='/') printf ("%d\n", f/l); Else if(a[i]=='%') printf ("%d\n", f%l); } return 0;}
01: Evaluation of simple arithmetic expressions
- View
- Submit
- Statistics
- Questions
-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
Describe
-
Simple arithmetic operations of two-bit positive integers (only integer operations are considered), arithmetic operations are:
+, addition operation;
-, subtraction operations;
*, multiplication operation;
/, integer division operation;
%, take the remainder operation.
The arithmetic expression is in the format (there may be spaces before and after the operator):
Arithmetic operators for arithmetic operations
Please output the corresponding results.
-
Input
-
An arithmetic expression of one line.
-
Output
-
The result of an integer arithmetic operation (the result value is not necessarily a 2-bit number, possibly more than 2 bits or less than 2 bits).
-
Sample input
-
32+64
-
Sample output
-
96
Original title: http://noi.openjudge.cn/ch0112/01/
Evaluation of simple arithmetic expressions