📄 shujujiegou.txt
字号:
#include "stdio.h"
#include "math.h"
#include"stdlib.h"
#define True 1
#define False 0
int T;
int operation(char op)
{
switch(op)
{case')':
case'(':
case'+':
case'-':
case'*':
case'/':return True;
default: return False;
}
}
void trans(char str[50],char exp[50])
{
char stack[50];
char ch;
int i,j,t,top=0;
t=1;
i=1;
ch=str[i];
i++;
while(ch!='#')
{
switch(ch)
{
case '(':
top++;
stack[top]=ch;
break;
case ')':
while(stack[top]!='(')
{
exp[t]=stack[top];
top--;
t++;
}
top--;
break;
case '+':
case '-':
while(top!=0&&stack[top]!='(')
{
exp[t]=stack[top];
top--;
t++;
}
top++;
stack[top]=ch;
break;
case '*':
case '/':
while(stack[top]=='*'||stack[top]=='/')
{exp[t]=stack[top];
top--;
t++;
}
top++;
stack[top]=ch;
break;
case' ':break;
default:
while(ch>='0'&&ch<='9')
{
exp[t]=ch;
t++;
ch=str[i];
i++;
}
i--;
exp[t]='#';
t++;
}
ch=str[i];
i++;
}
while(top!=0)
{
exp[t]=stack[top];
t++;
top--;
}
exp[t]='#';
T=t;
printf("Fu hao you xian shun xu:\n");
for(j=1;j<T;j++)
printf("%c",exp[j]);
printf("\n");
}
double count(char exp[50])
{
int i=1,n=0;
double result[50]={0.0};
while(i<T)
{
while(!(operation(exp[i])))
{
while((exp[i]!='#'))
{
result[n]=result[n]*10+(exp[i]-48);
i++;
}
n++;i++;
}
switch(exp[i])
{
case'+':result[n-2]=result[n-2]+result[n-1];
n--;result[n]=0;
break;
case'-':result[n-2]=result[n-2]-result[n-1];
n--;result[n]=0;
break;
case'*':result[n-2]=result[n-2]*result[n-1];
n--;result[n]=0;
break;
case'/':result[n-2]=result[n-2]/result[n-1];
n--;result[n]=0;
break;
}
i++;
}
return(result[0]);
}
main()
{
double e;int i=0,j=1,k=1,m,n,h,l;
char srr[50],rrp[50],epp[50],rrr[50];
char ch[50];
printf("qing shu biao da shi ( # jie shu)");
do{
i++;
scanf("%c",&srr[i]);
}while(srr[i]!='#');
getchar();
while((srr[j]!='#')&&(srr[j]!='|')&&(srr[j]!='!'))
j++;
if(srr[j]=='#')
{
trans(srr,epp);
}
else if((srr[j]=='|')){
n=j;
j++;
while(srr[j]!='|')
{
rrr[k]=srr[j];
k++;j++;
}
j++;
rrr[k]='#';
trans(rrr,rrp);
e=count(rrp);
m=(int)fabs((int)e);
k=1;
if(0<=m&&m<10)
{
ch[k]=m+48;
srr[n++]=ch[k];
}
else if(m>=10&&m<=99)
{
h=m/10; m=m%10;
srr[n++]=h+48;
srr[n++]=m+48;
}
else if(m>=100&&m<=999)
{
i=m/100;h=m/10%10;
k=m%100;
srr[n++]=i+48;
srr[n++]=h+48;
srr[n++]=k+48;
}
else
{
i=m/1000;
h=(m/100)%10;
k=(m/10)%10;
l=m%1000;
srr[n++]=i+48;
srr[n++]=h+48;
srr[n++]=k+48;
srr[n++]=l+48;
}
while(srr[j]!='#')
srr[n++]=srr[j++];
srr[n]='#';
trans(srr,epp);
}
else{
n=j;k=1;
j++;
while(srr[j]!='!')
{
rrr[k]=srr[j];
k++;j++;
}
j++;
rrr[k]='#';
trans(rrr,rrp);
e=count(rrp);
m=(int)sqrt(e);
k=1;
if(0<=m&&m<10)
{
ch[k]=m+48;
srr[n++]=ch[k];
}
else if(m>=10&&m<=99)
{
h=m/10; m=m%10;
srr[n++]=h+48;
srr[n++]=m+48;
}
else if(m>=100&&m<=999)
{
i=m/100;h=m/10%10;
k=m%100;
srr[n++]=i+48;
srr[n++]=h+48;
srr[n++]=k+48;
}
else
{
i=m/1000;
h=(m/100)%10;
k=(m/10)%10;
l=m%1000;
srr[n++]=i+48;
srr[n++]=h+48;
srr[n++]=k+48;
srr[n++]=l+48;
}
while((srr[j]!='#')&&(srr[j]!='|'))
srr[n++]=srr[j++];
srr[n]='#';
trans(srr,epp);
}
printf("\n");
e=count(epp);
printf("JIE GUO: \n");
printf("%lf",e);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -