andre_joy

导航

hdu 2526

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2526

题意:中文……下一行字符根据上一行对应三个字符来决定。

mark:无。

代码:

#include <stdio.h>
#include <string.h>

char a[2][510],b[8][4];
int f[8];

int tr(char c[])
{
    int i;
    for(i = 0; i < 8; i++)
        if(!strcmp(c, b[i])) return f[i];
}

int main()
{
    char c[4];
    int t,m,le;
    int i,j;
    scanf("%d", &t);
    while(t-- && scanf("%d", &m))
    {
        for(i = 0; i < 8; i++)
            scanf("%s %d", b[i], &f[i]);
        a[0][0] = a[1][0] = '0';
        scanf("%s", a[0]+1);
        puts(a[0]+1);
        le = strlen(a[0]);
        for(i = 1; i < m; i++)
        {
            for(j = 1; j < le; j++)
            {
                c[0] = a[!(i%2)][j-1];
                c[1] = a[!(i%2)][j];
                if(j == le-1) c[2] = '0';
                else c[2] = a[!(i%2)][j+1];
                c[3] = '\0';
                a[i%2][j] = tr(c)+'0';
            }
            puts(a[i%2]+1);
        }
    }
    return 0;
}

posted on 2012-07-01 13:57  andre_joy  阅读(164)  评论(0编辑  收藏  举报