锘??xml version="1.0" encoding="utf-8" standalone="yes"?>人妻少妇久久中文字幕一区二区,久久国产AVJUST麻豆,久久99精品国产麻豆婷婷http://m.shnenglu.com/lvlawliet/category/17991.htmlVIMzh-cnWed, 26 Oct 2011 02:25:30 GMTWed, 26 Oct 2011 02:25:30 GMT60JOJ1037錛歄perandhttp://m.shnenglu.com/lvlawliet/archive/2011/10/25/159078.htmlLLawlietLLawlietTue, 25 Oct 2011 11:53:00 GMThttp://m.shnenglu.com/lvlawliet/archive/2011/10/25/159078.htmlhttp://m.shnenglu.com/lvlawliet/comments/159078.htmlhttp://m.shnenglu.com/lvlawliet/archive/2011/10/25/159078.html#Feedback0http://m.shnenglu.com/lvlawliet/comments/commentRss/159078.htmlhttp://m.shnenglu.com/lvlawliet/services/trackbacks/159078.html

Professor Maple teaches mathematics in a university. He have invented a function for the purpose of obtaining the operands from an expression. The function named op(i,e) can be described as follows: The expression e may be divided into sub-expression(s) by the operator, which has the lowest priority in the expression. For example, the expression “a*b+b*c+c*d” should be divided into three sub-expressions “a*b”, “b*c” and “c*d”, because the operator “+” has the lowest priority. The purpose of this function is to extract the ith sub-expression as the result. So, in the example above, op(2,e)=b*c.

If we regard the sub-expression as the main expression, it might be divided again and again. Obviously, the dividing process is recursive. As you see, the following example is much more complex:

Let p:=a^b*c+(d*c)^f*z+b
op(1,op(1,op(2,p)))=(d*c)
op(1,op(1,op(1,op(2,p))))=d*c
op(2,op(2,p))=z
op(3,p)=b
op(1,op(3,p))=b

Professor Maple is so lazy that he would leave the work to computer rather than do it himself, when the expression is long and complicated. Of course, without your program, the computer won’t work out the result automatically.

Input

The input file contains several test cases. The last test case in the input file is followed by a line containing a symbol “*”, indicating the end of the input data. Each test case consists of two parts. The first part describes the expression, while the second part contains several questions, which should be calculated according to the expression.

The first line of each test case contains an expression consists of the expression name, “:=” and the content of the expression. The expression name is a lowercase. And the content is composed by lowercases and operators “+”, “(”, “)”, “*” and “^”. For example, here is a valid expression, p:=a^b*c+(d*c)^f*z+b. Among those operators, “(” and “)” have the highest priority. The operator “^” has a lower priority, and then “*”. The priority of the operator “+” is the lowest.

The second line of each test case contains an integer n indicating n questions based on the above expression. This is followed by n lines. Each of them contains the description of one question, which consists of integers. For example, the question with three integers “2 1 1” describes the function op(1,op(1,op(2,e))). To compute this function, we have to keep to the following sequence: First, according to the first integer 2, divide the expression and extract the 2nd sub-expression. Then, according to the second integer 1, divide the sub-expression and extract the 1st one. Finally, according to the third integer 1, divide the outcome again, and extract the result.

Output

For each test case, display the expression name and a colon on the first line. Then display the result of each question on a line. The layout of the output is shown in the sample output.

You may assume that all expressions and functions are always valid.

Display a blank line between test cases.

Sample Input

p:=a^b*c+(d*c)^f*z+b 
4
2 1 1
2 2
3
3 1
a:=(x+y)
3
1
1 2
1 2 1
*

Sample Output

Expression p: 
op(1,op(1,op(2,p)))=(d*c)
op(2,op(2,p))=z
op(3,p)=b
op(1,op(3,p))=b

Expression a:
op(1,a)=x+y
op(2,op(1,a))=y
op(1,op(2,op(1,a)))=y


妯℃嫙棰橈紝澶勭悊濂藉師瀛楃涓茬殑浼樺厛綰у氨琛屼簡銆?br />浠g爜錛?br />
#include <iostream>
#include 
<cstring>
#include 
<cstdio>
using namespace std;

int find(char c)
{
    
if (c == '(' || c == ')'return 4;
    
if (c == '^'return 3;
    
if (c == '*'return 2;
    
if (c == '+'return 1;
    
return 1000;
}

char s[101];
string e;
int n, i, j, k, p[101], r[101], v[101], head, tail, x, ri, d = 0;

int main()
{
    
while (scanf("%s", s), s[0!= '*')
    {
        
if (d++) puts("");
        head 
= 0;
        e 
= "";
        
while (s[head] != ':')
          e 
+= s[head++];
        head 
+= 2;
        printf(
"Expression %s:\n", e.c_str());
        tail 
= strlen(s) - 1;
        x 
= 0;
        
for (i = head; i <= tail; ++i)
        {
            
if (s[i] == ')') x -= 4;
            v[i] 
= find(s[i]) + x;
            
if (s[i] == '(') x += 4;
        }
        scanf(
"%d\n"&k);
        
for (i = 0; i < k; ++i)
        {
            ri 
= 0;
            
int head1 = 3, min1, t;
            tail 
= strlen(s);
            
char c;
            
while ((c = getchar()) != '\n')
            {
                cin.putback(c);
                scanf(
"%d"&n);
                r[ri
++= n;
                min1 
= 1000;
                
for (j = head1; j < tail; ++j)
                  
if (v[j] < min1) min1 = v[j];
                
if (s[head1] == '(' && s[tail - 1== ')' && min1 == v[head1])
                {
                    head1
++;
                    tail
--;
                }
                
else
                  
if (head1 + 1 == tail){}
                
else
                {
                    p[
0= head1 - 1;
                    
for (j = head1, t = 1; j < tail; ++j)
                      
if (v[j] == min1)
                      {
                          p[t
++= j;
                      }
                    p[t] 
= tail;
                    head1 
= p[n - 1+ 1;
                    tail 
= p[n];
                }
            }
            
for (j = ri - 1; j >= 0--j)
              printf(
"op(%d,", r[j]);
            printf(
"%s", e.c_str());
            
for (j = 0; j < ri; ++j)
              printf(
")");
            printf(
"=");
            
for (j = head1; j < tail; ++j)
                printf(
"%c", s[j]);
            puts(
"");
        }
    }
    
return 0;
}


LLawliet 2011-10-25 19:53 鍙戣〃璇勮
]]>
欧美亚洲国产精品久久高清| 一级做a爱片久久毛片| 奇米影视7777久久精品人人爽| 久久久久久久精品成人热色戒| 久久发布国产伦子伦精品| 久久免费国产精品| 国产精品久久久久久久久鸭| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 亚洲另类欧美综合久久图片区| 五月丁香综合激情六月久久| 99久久综合狠狠综合久久| 99久久国产精品免费一区二区| 国产成人无码精品久久久久免费 | 久久久亚洲精品蜜桃臀| 久久精品国产亚洲av高清漫画| 欧美激情精品久久久久久久| 久久99国产精品久久99| 久久精品国产久精国产一老狼| 国产精品久久久久久久午夜片| 99久久精品毛片免费播放| 精品久久久久久中文字幕大豆网| 久久久久国产日韩精品网站| 9999国产精品欧美久久久久久| 伊人精品久久久久7777| 日本加勒比久久精品| 久久久精品国产亚洲成人满18免费网站 | 久久久久久久精品妇女99| 深夜久久AAAAA级毛片免费看| 国产精品久久久久一区二区三区| AAA级久久久精品无码片| 波多野结衣中文字幕久久| 久久99久久99精品免视看动漫| 亚洲国产精品成人久久| 色综合久久久久综合体桃花网| 久久精品人人做人人妻人人玩| 狠狠色狠狠色综合久久| 亚洲人成网亚洲欧洲无码久久 | 色诱久久久久综合网ywww| 亚洲精品美女久久久久99| 久久精品国产亚洲AV香蕉| 国产精品美女久久久|