91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

四則表達式求真值表,支持與或非蘊含等 直接就應該可以用

資源截圖

代碼片段和文件信息

#?include?“stdio.h“
#?include?“ctype.h“
#?include?“string.h“
#?include?“stdlib.h“
#?include??“math.h“
#?define?MAXSIZE?100
typedef?char?elemtype;
typedef?struct{
elemtype?data[MAXSIZE];
int?top;
}sqstack;

void?init_sqsqstack(sqstack*S){
S->top?=?-1;
}

int?empty_sqstack(sqstack*S){
if?(S->top?==?-1)
return?1;
else
return?0;
}

void?push_sqstack(sqstack*S?elemtype?x){
if?(S->top?==?MAXSIZE?-?1)
{
printf(“出現錯誤!“);?return;
}
else
S->data[++(S->top)]?=?x;
}

void?pop_sqstack(sqstack?*S?elemtype?*x){
if?(S->top?==?-1)
{
printf(“出現錯誤!“);?return;
}
else{
*x?=?S->data[S->top];
S->top--;
}
}

void?top_sqstack(sqstack*S?elemtype*x){
if?(S->top?==?-1)
{
printf(“出現錯誤!“);?return;
}
else
*x?=?S->data[S->top];
}

int?pre(char?op){
switch?(op){
case‘>‘:
case‘=‘:return?1;?break;
case‘|‘:return?2;?break;
/*‘>’‘=’“|”“&”“~”優先級依次升高*/
case‘&‘:return?3;?break;
case‘~‘:return?4; break;
case‘(‘:
case‘#‘:
default:return?0;?break;
}
}

void?transform(char?suffix[]?char?exp[]){

sqstack?S;
char?ch;
int?i?=?0?j?=?0;
init_sqsqstack(&S);
push_sqstack(&S?‘#‘);
while?(exp[i]?!=?‘\0‘){
ch?=?exp[i];
switch?(ch){
case‘(‘:push_sqstack(&S?exp[i]);?i++;?break;
case‘)‘:while?(S.data[S.top]?!=?‘(‘){
pop_sqstack(&S?&ch);?suffix[j++]?=?ch;
}
pop_sqstack(&S?&ch);
i++;
break;
case‘|‘:
case‘&‘:
case‘~‘:
case‘=‘:
case‘>‘:
while?(pre(S.data[S.top])?>=?pre(exp[i])){
pop_sqstack(&S?&ch);
suffix[j++]?=?ch;
}
push_sqstack(&S?exp[i]);
i++;
break;
default:while?(isdigit(exp[i])){
suffix[j++]?=?exp[i];
i++;
}
}
}
while?(S.data[S.top]?!=?‘#‘){
pop_sqstack(&S?&ch);?suffix[j++]?=?ch;
}
suffix[j]?=?‘\0‘;
}

int?calculate_exp(char?exp[]){
sqstack?S;
int?i?=?0;
char?x?x1?x2;
init_sqsqstack(&S);
while?(exp[i]?!=?‘\0‘){
switch?(exp[i])?{
case‘|‘:
pop_sqstack(&S?&x2);
pop_sqstack(&S?&x1);
x?=?(x1?-?‘0‘)?||?(x2?-?‘0‘);
push_sqstack(&S?(x?+?‘0‘));
i++;?break;
//跳出尋找下一次
case‘=‘:
pop_sqstack(&S?&x2);
pop_sqstack(&S?&x1);
x?=?(x1?==?x2);
push_sqstack(&S?(x?+?‘0‘));
i++;?break;
case‘>‘:
pop_sqstack(&S?&x2);
pop_sqstack(&S?&x1);
x?=?!(x1?-?‘0‘)?||?(x2?-?‘0‘);
push_sqstack(&S?(x?+?‘0‘));
i++;?break;
case‘&‘:
pop

評論

共有 條評論