• <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)  編輯 收藏 引用 所屬分類: 模擬題
            国产AV影片久久久久久| 97精品国产97久久久久久免费 | 久久亚洲国产最新网站| 三级三级久久三级久久| 欧美一区二区三区久久综合 | 久久亚洲私人国产精品vA| 99久久精品国内| 久久一区二区三区免费| 中文字幕热久久久久久久| 亚洲成色999久久网站| 久久这里都是精品| 久久香蕉国产线看观看99| 免费精品国产日韩热久久| 99久久综合狠狠综合久久止| 久久久久亚洲?V成人无码| 久久香蕉超碰97国产精品| 精品久久久久国产免费| 久久不见久久见免费视频7| 四虎国产精品成人免费久久| 国产欧美久久一区二区| 欧美精品九九99久久在观看| 久久久久久久尹人综合网亚洲 | 久久精品欧美日韩精品| 亚洲午夜无码AV毛片久久| 久久99精品综合国产首页| 久久九九兔免费精品6| 久久精品一区二区三区中文字幕| 久久水蜜桃亚洲av无码精品麻豆| 香蕉aa三级久久毛片| 国产免费福利体检区久久| 狠狠干狠狠久久| 久久精品人人槡人妻人人玩AV| 日本五月天婷久久网站| 一本久久精品一区二区| 欧美一级久久久久久久大| 99久久精品无码一区二区毛片| www.久久99| 国产精品久久自在自线观看| 久久ww精品w免费人成| 99麻豆久久久国产精品免费 | 久久性精品|