*1397简单算术表达式求值

Posted TFLSNOI

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了*1397简单算术表达式求值相关的知识,希望对你有一定的参考价值。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 char a[20];
 5 using namespace std;
 6 int js(int x,int y,char f)
 7 {
 8     switch(f)
 9     {
10         case +:cout<<x+y;break;
11         case -:cout<<x-y;break;
12         case *:cout<<x*y;break;
13         case /:cout<<x/y;break;
14         case %:cout<<x%y;break;
15     }
16     
17 } 
18 int main()
19 {
20     gets(a);
21     int len=strlen(a);
22     int b[5],j=0,x,y;
23     char f;
24     for(int i=0;i<len;i++)
25     {
26         if(a[i]>=0&&a[i]<=9)b[j++]=a[i]-0;
27         else if (a[i]!= )f=a[i];
28     }
29     x=b[0]*10+b[1];
30     y=b[2]*10+b[3];
31     js(x,y,f);
32     return 0;
33 }

 

以上是关于*1397简单算术表达式求值的主要内容,如果未能解决你的问题,请参考以下文章

C++:算术表达式求值

Go 表达式求值器

栈的应用—算术表达式求值

判断C语言算术表达式的合法性

java实现算术表达式求值

求C++ 表达式求值得程序,最好简单说明数据结构和大致方法