Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the judgment of closed Formula in C language

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to realize the judgment of combined formula in C language". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "how to realize the judgment of closed formula in C language". Let's study and learn together.

Combined formula

It is obvious that it is relatively easy to use recursion to simulate the judgment process. (of course, using the stack, loop implementation is also OK, after all, recursion occurs in the stack area (function stack frame), in addition, recursive solution to deal with a lot of details, the loop will be more troublesome).

From the definition of the combined formula, it is obvious that the atomic formula is our recursive exit, which determines the exit, and the rest is how to get to this exit through the recursive algorithm.

Agree to replace non-conjunctions! Conjunctive (^) * (quantitative product) disjunctive (V) + (quantitative sum) implied (- >) > equivalent =

Train of thought

Delete negative connectives

The idea is to use an auxiliary array to occupy time and store non! And then copy it to the original interval, but assign a value to the original interval\ 0

Void Del_Negation (char* str,int n) {assert (str); char* tmp = (char*) calloc (nasty 1, sizeof (char)); / / one more 1 is used to place\ 0 to prevent strcpy from copying assert (tmp) across boundaries; int cnt = 0; int I = 0; while (I)

< n)//将除!的字符赋值到tmp中 { if (str[i] != '!') { tmp[cnt++] = str[i]; } ++i; } memset(str, 0, sizeof(char)*n);//对str那块内存重新赋值为\0,防止tmp拷贝到str中后,s扔有旧的数据 strcpy(str, tmp); free(tmp); tmp = NULL;}删除括号 删除括号,因为是对首尾进行的删除,这里通过2次strcpy就可以完成 void Del_Bracket( char* str, int left, int right){ assert(str); char* tmp = (char*)calloc(right - left +1+1, sizeof(char)); assert(tmp); str[right] = '\0'; strcpy(tmp, str+left+1); strcpy(str+left, tmp);}第一个联结词的下标 找寻区间中第一双目运算符:找到就返回下标,否则就返回0. int Find_Fist_operator( char* str, int left, int right){ int ret = 0; while (left(B) { int keyi = Find_Fist_operator(str, left, right);//找寻第一个双目运算符 if (keyi >

0) {if (str [keyi + 1] = ='(') / / A

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report