给大家推荐个靠谱的公众号程序员探索之路,大家一起加油
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>//头文件包含遇到字母,数字函数
#define N 1001
using namespace std;
char ch1[N];//数组模拟栈进行计算
double ch2[N];
double ji(char a,int m,int n)
{
char x='d',y='a',z='i';
if(a==x) return (m+n);
if(a==y) return m>n?m:n;
if(a==z) return m<n?m:n;
}
void sum()
{
char s[300],a[5],b;
scanf("%s",s);
int k,l,top1=-1,top2=-1;
double m,n;
k=strlen(s);
for(int i=0;i<k;)
{
if(isalpha(s[i]))//判断s[i]是否是字符
{
top1++;
ch1[top1]=s[i+1];//只需知道中间的字母即可
i+=4;//把(号也跳过去了
}
else if(isdigit(s[i]))//判断s[i]是否是数字
{
l=0;
while(isdigit(s[i]))
{
a[l]=s[i];
l++;
i++;
}
a[l]='\0';
top2++;
ch2[top2]=atof(a);
}
else if(s[i]==')')
{
m=ch2[top2];
top2--;
n=ch2[top2];
top2--;
b=ch1[top1];
top1--;
top2++;
ch2[top2]=ji(b,m,n);
i++;
}
else i++;//遇到,号也跳过
}
printf("%.0lf\n",ch2[top2]);
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
sum();
}
return 0;
}