码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 785 Grid Colouring

时间:2017-06-06 23:22:55      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:log   while   提交   ret   closed   div   相等   close   dir   

题意大概说 分块填充字符的,题目数据一看就知道,这个题跟uva的784一样。

注意点: 不要被测试数据骗了,填充的不一定是 ‘/’ 或者 ‘#’ 还可能是除了空格和‘X‘ 之外的字符。

真是装逼遭雷劈啊,我没看题,就看个样例输出 就直接打了,提交错。感觉挺对,后来才发现被测试数据骗了。

另外的注意点就是  初始化。啊啊啊 我没加,一下把之前的所有字符串都给输出来了。妈卖批..好题专坑我这等马虎虫....

最后注意点 每行字符串长度不一定都相等,是参差不齐的!!!ok 附上丑陋的代码

 

技术分享
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str[40][90];
int ww[40],k;
int dir[4][2] = {0,1,1,0,0,-1,-1,0};
void dfs(int x,int y,char c)
{
    str[x][y] = c;
    for(int i = 0; i < 4; i++)
    {
        int tx = x + dir[i][0];
        int ty = y + dir[i][1];
        if(tx >= 0 && tx < k && ty >= 0 && ty < ww[tx] && str[tx][ty] ==  )
            dfs(tx,ty,c);
    }
}
int main()
{
    int i = 0,j= 0;
    while(gets(str[i]))
    {
        ww[i] = strlen(str[i]);
        i++;
        while(gets(str[i]))
        {
            if(str[i][0] == _) break;
            else
            {
                ww[i] = strlen(str[i]);
                i++;
            }
        }
        k = i;
        for(i = 0; i < k; i++)
        {
            for(j = 0; j < ww[i]; j++)
            {
                if(str[i][j] !=   && str[i][j] != X)
                    dfs(i,j,str[i][j]);
            }
        }
        for(i = 0; i < k; i++)
            printf("%s\n",str[i]);
        printf("%s\n",str[k]);
        i = 0;  // 注意初始化  啊啊啊 !!!  焦人
    }
    return 0;
}
View Code

 

UVA - 785 Grid Colouring

标签:log   while   提交   ret   closed   div   相等   close   dir   

原文地址:http://www.cnblogs.com/wangshuazi/p/6953743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!