Evaluation of simple arithmetic expressions

Source: Internet
Author: User
Tags integer division



#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

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.