• <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>

            gzwzm06

              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              1 隨筆 :: 52 文章 :: 17 評(píng)論 :: 0 Trackbacks
            需要處理好數(shù)據(jù)的輸入,我在這里WA了幾次
              1
              2#include <iostream>
              3#include <cstdio>
              4#include <cstring>
              5using namespace std;
              6
              7const int SIZE = 50;
              8const int MAX = 200;
              9const int LEN = 5000;
             10
             11struct QUILT
             12{
             13    char effect[2][5];
             14}
            quilt[6];
             15
             16struct NODE
             17{
             18    int map[SIZE][SIZE];
             19    int ht, wt;
             20}
            node[MAX];
             21
             22char exp[LEN];
             23int gLen, gPos, temp[SIZE][SIZE], start;
             24bool mark;
             25
             26void Init()
             27{
             28    strcpy(quilt[0].effect[0],"//");
             29    strcpy(quilt[0].effect[1],"/+");
             30    strcpy(quilt[1].effect[0],"\\\\");
             31    strcpy(quilt[1].effect[1],"+\\");
             32    strcpy(quilt[2].effect[0],"+/");
             33    strcpy(quilt[2].effect[1],"//");
             34    strcpy(quilt[3].effect[0],"\\+");
             35    strcpy(quilt[3].effect[1],"\\\\");
             36    strcpy(quilt[4].effect[0],"--");
             37    strcpy(quilt[4].effect[1],"--");
             38    strcpy(quilt[5].effect[0],"||");
             39    strcpy(quilt[5].effect[1],"||");
             40
             41    gLen = gPos = 0;
             42}

             43
             44bool Is(char ch)
             45{
             46    if ( ch == ';' || ch == ',' || ch == '(' || ch == ')' 
             47        || isalpha(ch) )
             48        return true;
             49    return false;
             50}

             51
             52inline int GetValue(const int& s)
             53{
             54    switch(s)
             55    {
             56    case 0:
             57        return 1;
             58    case 1:
             59        return 2;
             60    case 2:
             61        return 3;
             62    case 3:
             63        return 0;
             64    case 4:
             65        return 5;
             66    case 5:
             67        return 4;
             68    }

             69
             70    return -1;
             71}

             72
             73void Turn(const int& p)
             74{
             75    int i, j, k, l, t;
             76
             77    for ( i = 0, k = node[p].ht - 1; i < node[p].ht; ++i, --k )
             78        for ( j = 0, l = 0; j < node[p].wt; ++j, ++l )
             79        {
             80            temp[j][i] = GetValue( node[p].map[k][l] );
             81        }

             82
             83    t = node[p].ht; node[p].ht = node[p].wt; node[p].wt = t;
             84
             85    for ( i = 0; i < node[p].ht; ++i )
             86        for ( j = 0; j < node[p].wt; ++j )
             87            node[p].map[i][j] = temp[i][j];
             88}

             89
             90bool Sew(const int& a, const int& b)
             91{
             92    if ( node[a].ht != node[b].ht )
             93    {
             94        mark = true;
             95        return false;
             96    }

             97
             98    int i, j, k;
             99
            100    for ( i = 0; i < node[a].ht; ++i )
            101        for ( j = node[a].wt, k = 0; k < node[b].wt; ++j, ++k )
            102            node[a].map[i][j] = node[b].map[i][k];
            103
            104    node[a].wt += node[b].wt;
            105
            106    return true;
            107}

            108
            109int Solve()
            110{
            111    if ( mark )
            112        return -1;
            113    int a = 0, b;
            114
            115    if ( exp[start] == 's' )
            116    {
            117        start += 4;
            118        a = Solve();
            119        start++;
            120
            121        if ( a == -1 )
            122            return -1;
            123
            124        b = Solve();
            125
            126        if ( b == -1 )
            127            return -1;
            128
            129        if ( !Sew( a, b ) )
            130            a = -1;
            131        start++;
            132    }

            133    else if ( exp[start] == 't' )
            134    {
            135        start += 5;
            136        a = Solve();
            137        start++;
            138        if ( a == -1 )
            139            return -1;
            140        Turn( a );
            141    }

            142    else if ( exp[start] == 'A' || exp[start] == 'B' )
            143    {
            144        a = gPos;
            145        node[gPos].wt = node[gPos].ht = 1;
            146        
            147        if ( exp[start] == 'B' )
            148            node[gPos].map[0][0= 4;
            149        else 
            150            node[gPos].map[0][0= 0;
            151        gPos++;
            152        start++;
            153    }

            154
            155    return a;
            156}

            157
            158void Output( const int& p )
            159{
            160    int i, j, k;
            161
            162    for ( i = 0; i < node[p].ht; ++i )
            163    {
            164        for ( k = 0; k < 2++k )
            165        {
            166            for ( j = 0; j < node[p].wt; ++j )
            167            {
            168                for ( int l = 0; l < 2++l )
            169                    printf("%c", quilt[node[p].map[i][j]].effect[k][l]);
            170            }

            171            printf("\n");
            172        }

            173    }

            174}

            175
            176int main()
            177{
            178//    freopen("1.txt", "r", stdin);
            179
            180    Init();
            181
            182    char ch;
            183    int p, t = 1;
            184    gLen = gPos = 0;
            185    mark = false;
            186
            187    while ( cin >> ch )
            188    {        
            189        if ( Is(ch) )
            190        {
            191            if ( ch == ';' )
            192            {
            193                exp[gLen++= ch;
            194
            195                printf("Quilt %d:\n", t);
            196
            197                start = 0;
            198                p = Solve();
            199
            200                if ( p == -1 || mark ) {
            201                    printf("error\n");
            202                }

            203                else {
            204                    Output(p);
            205                }

            206                t++;
            207                gLen = gPos = 0;
            208                mark = false;
            209            }

            210            else
            211                exp[gLen++= ch;
            212        }

            213    }

            214
            215    return 0;
            216}

            217
            posted on 2009-03-27 10:42 閱讀(209) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 模擬題
            亚洲国产精品久久66| 亚洲国产天堂久久综合网站| 亚洲综合久久综合激情久久| 国产一区二区三区久久精品| 潮喷大喷水系列无码久久精品| 伊人久久综在合线亚洲2019| 久久国产精品波多野结衣AV| 久久强奷乱码老熟女网站| 色偷偷久久一区二区三区| 国产精品99久久久久久董美香| 久久精品中文字幕有码| 中文字幕日本人妻久久久免费| 成人久久综合网| 女人高潮久久久叫人喷水| 狠狠色丁香久久综合五月| 日韩美女18网站久久精品| 久久久久亚洲av无码专区导航| 日本免费久久久久久久网站| 日本WV一本一道久久香蕉| 成人久久久观看免费毛片| 奇米影视7777久久精品人人爽| 国产情侣久久久久aⅴ免费| 久久久久亚洲av成人无码电影| 久久99国产综合精品女同| 伊色综合久久之综合久久| 99久久精品费精品国产一区二区| 狠狠色丁香婷婷久久综合| 丰满少妇人妻久久久久久4| 国产A级毛片久久久精品毛片| 久久99久久成人免费播放| 久久久91精品国产一区二区三区 | 久久中文娱乐网| 久久精品国产免费观看三人同眠| 91精品国产91久久| 久久精品国产第一区二区三区| 久久精品国产清自在天天线| 一级a性色生活片久久无| 久久久久亚洲AV无码去区首| 国产成人精品久久亚洲高清不卡 | 国产V亚洲V天堂无码久久久| 99久久精品午夜一区二区|