K - The Hive

K - The Hive
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

There is a hive in the village. Like this. There are 9 columns (from A to I) in this hive. Different column may have the different number of grids. Every grid has its own coordinate, which is form by a uppercase letter and a digit. The uppercase letter discribes which column the grid is, the digit discribes which row the grid is.

As the figure shows, column A has 7 grids, column B has 8 grids, column C has 9 grids, column D has 10 grids, column E has 11 grids, column F has 10 grids, column G has 9 grids, column H has 8 grids, column I has 7 grids. The grid in the bottom has the lowest row coordinate which is 0.

There are 26 kinds of honey. At the beginning, all grids in the hive are empty. Everyday, the bee in this hive will drop a kind of honey from the top of one of these 9 columns. The lowest empty grid of this column will be filled with this kind of honey. And if the grid under it adjacently has the same kind of honey as it did, these two grids will generate a candy. And these two grids will be empty immediately.

Because these columns only have a few grids, they may be full one day. If the column the bee drops on is full, this drop will not affect the hive.

Input

There are multiple cases (<20).

The first line containing an integer n (1 <= n <= 10000) indicates that the bee will work for n days. Following n lines, each line contains two charater. The fisrt one indicates which column will the bee drop the honey, the second charater indicates which kind of honey does the bee drop that day.

Output

First,print one line in the form "The number of candy is num_of_candy.". 
And then, display the hive. Extra space at the end of line is not allowed.

Sample Input

5
AE
BH
CI
DF
AE

Sample Output

The number of candy is 1.
         _
       _/ \_
     _/ \_/ \_
   _/ \_/ \_/ \_
 _/ \_/ \_/ \_/ \_
/ \_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
/ \_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
/ \_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
/ \_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
/ \_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
/ \_/ \_/ \_/ \_/ \
\_/ \_/ \_/ \_/ \_/
/ \_/ \_/ \_/ \_/ \
\_/H\_/ \_/ \_/ \_/
  \_/I\_/ \_/ \_/
    \_/F\_/ \_/
      \_/ \_/
        \_/



比较恶心的模拟题,题意是说告诉你N个操作,每个操作两个字符a,b表示往a管里添加b这个字符,如果在同一个管里有相邻的两个相同字符就消除掉,然后让你输出一共被消除了多少次,以及输出最后的样子。


处理的时候要注意如果某个管子被填满了,那么是不能再加进去的。就是说在管子外就算有一样的也不能消除。


因为自己比较蠢所以把判断是否满了的条件写错地方导致无限wa。


另:这种写法实际上是非常费时间以及丑陋的,所以有时间再考虑一下其他写法。


#include"iostream"
#include"cstring"
#include"cstdio"

using namespace std;

char maze[10][15];
int t[10] = {7,8,9,10,11,10,9,8,7};

void init()
{
    for(int i = 0;i < 10;i++)
    {
        for(int j = 0;j < 15;j++)
        {
            maze[i][j] = ' ';
        }
    }
}

int main(void)
{
    int n;
    while(~scanf("%d",&n))
    {
        init();
        char s[5];
        int ans = 0;
        int pos[10];
        memset(pos,0,sizeof(pos));
        for(int i = 0;i < n;i++)
        {
            scanf("%s",s);
            int mar = s[0] - 'A';
            if(pos[mar] == 0)
            {
                maze[mar][pos[mar]++] = s[1];
            }
            else
            {
                if(pos[mar] == t[mar]) continue;   //之前加到了下面那个if循环里结果WA了一万年
                if(maze[mar][pos[mar]-1] == s[1])
                {
                    ans ++;
                    pos[mar] --;
                    maze[mar][pos[mar]] = ' ';
                }
                else
                {
                    maze[mar][pos[mar]++] = s[1];
                }
            }
        }

        printf("The number of candy is %d.\n",ans);
        cout << "         _" << endl;
        cout << "       _/" << maze[4][10] << "\\_" << endl;
        cout << "     _/" << maze[3][9] << "\\_/" << maze[5][9] << "\\_" << endl;
        cout << "   _/" << maze[2][8] << "\\_/" << maze[4][9] << "\\_/" << maze[6][8] << "\\_" << endl;
        cout << " _/" << maze[1][7] << "\\_/" << maze[3][8] << "\\_/" << maze[5][8] << "\\_/" << maze[7][7] << "\\_" << endl;

        cout << "/" << maze[0][6] << "\\_/" << maze[2][7] << "\\_/" << maze[4][8] << "\\_/" << maze[6][7] << "\\_/" << maze[8][6] << "\\" << endl;
        cout << "\\_/" << maze[1][6] << "\\_/" << maze[3][7] << "\\_/" << maze[5][7] << "\\_/" << maze[7][6] << "\\_/" << endl;
        cout << "/" << maze[0][5] << "\\_/" << maze[2][6] << "\\_/" << maze[4][7] << "\\_/" << maze[6][6] << "\\_/" << maze[8][5] << "\\" << endl;
        cout << "\\_/" << maze[1][5] << "\\_/" << maze[3][6] << "\\_/" << maze[5][6] << "\\_/" << maze[7][5] << "\\_/" << endl;
        cout << "/" << maze[0][4] << "\\_/" << maze[2][5] << "\\_/" << maze[4][6] << "\\_/" << maze[6][5] << "\\_/" << maze[8][4] << "\\" << endl;
        cout << "\\_/" << maze[1][4] << "\\_/" << maze[3][5] << "\\_/" << maze[5][5] << "\\_/" << maze[7][4] << "\\_/" << endl;
        cout << "/" << maze[0][3] << "\\_/" << maze[2][4] << "\\_/" << maze[4][5] << "\\_/" << maze[6][4] << "\\_/" << maze[8][3] << "\\" << endl;
        cout << "\\_/" << maze[1][3] << "\\_/" << maze[3][4] << "\\_/" << maze[5][4] << "\\_/" << maze[7][3] << "\\_/" << endl;
        cout << "/" << maze[0][2] << "\\_/" << maze[2][3] << "\\_/" << maze[4][4] << "\\_/" << maze[6][3] << "\\_/" << maze[8][2] << "\\" << endl;
        cout << "\\_/" << maze[1][2] << "\\_/" << maze[3][3] << "\\_/" << maze[5][3] << "\\_/" << maze[7][2] << "\\_/" << endl;
        cout << "/" << maze[0][1] << "\\_/" << maze[2][2] << "\\_/" << maze[4][3] << "\\_/" << maze[6][2] << "\\_/" << maze[8][1] << "\\" << endl;
        cout << "\\_/" << maze[1][1] << "\\_/" << maze[3][2] << "\\_/" << maze[5][2] << "\\_/" << maze[7][1] << "\\_/" << endl;
        cout << "/" << maze[0][0] << "\\_/" << maze[2][1] << "\\_/" << maze[4][2] << "\\_/" << maze[6][1] << "\\_/" << maze[8][0] << "\\" << endl;
        cout << "\\_/" << maze[1][0] << "\\_/" << maze[3][1] << "\\_/" << maze[5][1] << "\\_/" << maze[7][0] << "\\_/" << endl;

        cout << "  \\_/" << maze[2][0] << "\\_/" << maze[4][1] << "\\_/" << maze[6][0] << "\\_/" << endl;
        cout << "    \\_/" << maze[3][0] << "\\_/" << maze[5][0] << "\\_/" << endl;
        cout << "      \\_/" << maze[4][0] << "\\_/" << endl;
        cout << "        \\_/" << endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值