• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              1 隨筆 :: 52 文章 :: 17 評論 :: 0 Trackbacks
            需要處理好數據的輸入,我在這里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 閱讀(215) 評論(0)  編輯 收藏 引用 所屬分類: 模擬題
            国内精品久久久久久麻豆| 久久久噜噜噜久久| 国产午夜精品久久久久免费视| 免费无码国产欧美久久18| 久久国产精品一国产精品金尊| 国产精品美女久久久久| 99久久精品无码一区二区毛片| 一本大道久久香蕉成人网| 久久综合综合久久综合| 久久国产成人精品麻豆| 国产精品中文久久久久久久| 2021少妇久久久久久久久久| 亚洲а∨天堂久久精品| 久久久久久九九99精品| 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久这里只有精品首页| 国产激情久久久久影院小草 | 国产成人精品久久综合| 久久久久久综合网天天| 国产精品99久久精品爆乳| 久久国产色AV免费看| 丁香色欲久久久久久综合网| 久久精品国产精品亜洲毛片| 国产人久久人人人人爽| 久久精品人人做人人爽电影| 99久久亚洲综合精品网站| 国产精品久久久久久吹潮| 久久亚洲国产成人影院| 欧美精品丝袜久久久中文字幕 | 久久久久噜噜噜亚洲熟女综合 | 久久精品黄AA片一区二区三区| 欧美日韩久久中文字幕| 伊人 久久 精品| 精品久久久久久无码中文字幕| 狠狠色丁香婷综合久久| 久久精品国产亚洲av影院| 亚洲国产视频久久| 亚洲欧美成人久久综合中文网| 久久99精品久久久久久水蜜桃| 国产AⅤ精品一区二区三区久久| 国内精品久久久久久久亚洲|