摘要: n圆括号和方括号,其嵌套的顺序随意。如([]())或[([ ][ ])]等为正确的匹配;而[( ])或([ ]( )或 ( ( ) ) )均为错误的匹配。 这里只介绍了()【】其实加上{}是一样的性质 看代码 1 #include<stdio.h> 2 #include<string.h> 3 int sw(char str) 4 { 5 if(str == '(') 6 return 1; 7 else 8 if(str == ')') 9 return 9;10 else11 if(str == '['... 阅读全文
posted @ 2012-02-11 19:12 _雨 阅读(333) 评论(0) 推荐(0) 编辑
摘要: 后缀式求值的方法参见我的另一篇文章 把运算符变成表达式 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int top = 0,i,k,s,num[50]; 6 char str; 7 while(scanf("%c", &str),str!='#') 8 { 9 if(str>='0'&&str<='9')10 num[++top] = str-48;11 else12 {13 switch(s 阅读全文
posted @ 2012-02-11 19:09 _雨 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int n,m,num[10000],x,y,z,d,f = 1,i,r = 0; 6 char str[10]; 7 scanf("%d", &m); 8 for(i = 1 ; i <= m;i++) 9 scanf("%d", &num[i]);10 scanf("%d",&n);11 r = m;12 while(n--)13 {14 scanf(&quo 阅读全文
posted @ 2012-02-11 19:08 _雨 阅读(344) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 int main() 3 { 4 int n,m,i,r,top = 0; 5 char stack[100]; 6 scanf("%d%d", &n,&m); 7 while(n) 8 { 9 top++;10 stack[top] = n%m;11 n = n/m;12 }13 while(top!=0)14 {15 printf("%d", stack[top]);16 top--;17 }1... 阅读全文
posted @ 2012-02-11 19:07 _雨 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 1 /* 将中缀表达式(a+b)转换为后缀表达式(ab+)的算法思想: 2 ·当读到数字直接送至输出队列中 3 ·当读到运算符t时, 4 a.将栈中所有优先级高于或等于t的运算符弹出,送到输出队列中; 5 b.t进栈 6 ·读到左括号时总是将它压入栈中 7 ·读到右括号时,将靠近栈顶的第一个左括号上面的运算符全部依次弹出,送至输出队列后,再丢弃左括号。 8 9 运用后缀表达式进行计算的具体做法: 10 ·建立一个栈S 11 ·从左到右读后缀表达式,读到数字就将... 阅读全文
posted @ 2012-02-11 14:21 _雨 阅读(799) 评论(4) 推荐(0) 编辑