问题补充说明:输入一个表达式,如3+4*2-4/2,然后输出结果9。数字为整数,没有括号。要求不用栈就能实现(因为还没学)。如果能打代码的话最好发代码,如果不方便的话能不能跟我讲一下大概思路,我主... 输入一个表达式,如3+4*2-4/2,然后输出结果9。数字为整数,没有括号。要求不用栈就能实现(因为还没学)。如果能打代码的话最好发代码,如果不方便的话能不能跟我讲一下大概思路,我主要不太明白怎么确定先算哪一步(即优先级)。感谢大神! 展开
//注意:表达式的格式是像这样的(末尾无=)走列迅地:
//10-5+4+6/360问答2*14*8/4-5*7+2-4*6/2-10*4-6/3
#inclu而晚评群破目县要de
intjisuan(intnum1,charop1,intnum2)
{
switch静溶刑模快刻(op1)
{
case'*':
returnnum1*num2;
cas井倒每作岁e'/':
returnnum1/num2;
case'+':
returnnum1+num2;
case'-':
returnnum1-num2;
}
}
intpro游cess(intnum1,charop1,intnum2)
{
intr,num3;
charop2;
if('\n'!=(op2=getchar()))
{
scanf("%d",&num3);
if('+'==op2||'-'==op2)
{
num1=jisuan(num1,op1,num2);
r=process(num1,op2,num3);
}
elseif('*'==op2||'/'==op2)
{
num2=jisuan(num2,op2,num3);
r=process(num1,op1,num2);
}
}
else
{
r=jisuan(num1,op呀包灯1,num2);
}
returnr;
}
intmain()
{
intnum1,num2;
charop;
printf("请输入一个表达式:");
scanf("%d%c%d",&num1,&op,&num2);
printf("=%d\n",process(num1,op,num2));
//标记
printf("\n\n\n");
charmymy[8]={37,28,14,6,29,8,42,25};
charmymystr[]={守清-21,-50,-69,-62,-妈掌赶52,-13,-19,-14,
-25,-9,93,86,43,61,18,77,17,-65,-94,-78,
-17,查话行状村仅镇矛值概-73,-128,-8上重快王波7,-4,-86,-58,-4状8,-73,-67,
-22,120,85,108,-60,-30,-43,-29,-8,-94,
-22,-34,-66,-49,-66,-8析补7,'\0'};
intxi=0;
for(xi=0;mymystr[xi];xi++)
m展孙体群厂ymystr[xi]^=mymy[xi%8];
puts(mymystr);
printf("\n\n\n");
//标记
return0;
}