• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj1068

            Parencodings
            Time Limit: 1000MS
            Memory Limit: 10000K
            Total Submissions: 13525
            Accepted: 8049

            Description

            Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:
            q By an integer sequence P = p1 p2...pn where pi is the number of left parentheses before the ith right parenthesis in S (P-sequence).
            q By an integer sequence W = w1 w2...wn where for each right parenthesis, say a in S, we associate an integer which is the number of right parentheses counting from the matched left parenthesis of a up to a. (W-sequence).

            Following is an example of the above encodings:

            S (((()()())))
            P-sequence 4 5 6666
            W-sequence 1 1 1456

            Write a program to convert P-sequence of a well-formed string to the W-sequence of the same string.

            Input

            The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case is an integer n (1 <= n <= 20), and the second line is the P-sequence of a well-formed string. It contains n positive integers, separated with blanks, representing the P-sequence.

            Output

            The output file consists of exactly t lines corresponding to test cases. For each test case, the output line should contain n integers describing the W-sequence of the string corresponding to its given P-sequence.

            Sample Input

            2
            6 
            4 5 6 6 6 6 
            9
            4 6 6 6 6 8 9 9 9 

            Sample Output

            1 1 1 4 5 6 
            1 1 2 4 5 1 1 3 9

            有點(diǎn)亂,感覺(jué)方法好多,就是不知道怎么寫……
             1 #include<stdio.h>
             2 #include<string.h>
             3 #include<math.h>
             4 int t,n,a[30];
             5 int sec,i,j,k,top;
             6 int stack[50],ans[50];
             7 void printtest()
             8 {
             9     int i;
            10     for (i=1;i<=top ;i++ )
            11         if (stack[i]==-1) printf("(");
            12     else printf(")");
            13 }
            14 int main()
            15 {
            16     scanf("%d",&t);
            17     for (j=1;j<=t ;j++ )
            18     {
            19         scanf("%d",&n);
            20         a[0]=0;
            21         top=0;
            22         for (i=1;i<=n ;i++ )
            23         {
            24             scanf("%d",&a[i]);
            25             if (a[i]!=a[i-1])
            26             {
            27                 for (k=a[i-1]+1;k<=a[i] ;k++ )
            28                 {
            29                     top++;
            30                     stack[top]=-1;//-1表示右括號(hào)
            31                 }
            32                 top++;
            33                 stack[top]=1;//1表示左括號(hào)
            34             }
            35             else 
            36             {
            37                 top++;
            38                 stack[top]=1;
            39             }
            40         }
            41         //printtest();//檢查
            42         ans[0]=0;
            43         for (i=1;i<=top ;i++ )
            44         if (stack[i]==1)
            45         {
            46             sec=1;
            47             k=i-1;
            48             while (sec!=0
            49             {
            50                 sec=sec+stack[k];
            51                 k--;
            52             }
            53             ans[0]++;
            54             ans[ans[0]]=(i-k+1)/2;
            55         }
            56         for (i=1;i<ans[0] ;i++ ) printf("%d ",ans[i]);
            57         printf("%d\n",ans[ans[0]]);
            58     }
            59     return 0;
            60 }
            61 

            posted on 2012-02-01 13:20 jh818012 閱讀(327) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄](méi)
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            久久99精品综合国产首页| 99久久人妻无码精品系列蜜桃| 亚洲精品美女久久777777| 久久精品成人影院| 久久中文字幕视频、最近更新| 亚洲欧美国产精品专区久久| 国产精品一区二区久久精品涩爱| 亚洲国产天堂久久久久久| 久久久无码精品亚洲日韩蜜臀浪潮| 久久久精品国产免大香伊| 亚洲欧美伊人久久综合一区二区 | 久久久久久午夜精品| 99久久精品免费看国产一区二区三区 | 国产∨亚洲V天堂无码久久久| 亚洲人成伊人成综合网久久久| 99精品国产综合久久久久五月天| 一本色综合网久久| 久久国产乱子伦精品免费强| 久久天天躁狠狠躁夜夜不卡| 久久不见久久见免费视频7| 色8激情欧美成人久久综合电| 亚洲国产精品无码久久久秋霞2 | 久久国产成人精品国产成人亚洲| 狠狠精品久久久无码中文字幕| 久久狠狠色狠狠色综合| 一本久久免费视频| 国产福利电影一区二区三区,免费久久久久久久精 | 久久久久亚洲国产| 久久国产精品无码网站| 国产精品青草久久久久婷婷| 精品伊人久久大线蕉色首页| 99久久精品九九亚洲精品| A狠狠久久蜜臀婷色中文网| 狠狠色综合网站久久久久久久高清| 亚洲国产成人久久综合一区77| 青青草原1769久久免费播放| 亚洲∧v久久久无码精品| 无码八A片人妻少妇久久| 色老头网站久久网| 久久人人爽人人爽人人片AV高清| 久久这里有精品视频|