#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<iterator>
#include<cstring>
#include<set>

using namespace std;
int m;
int n;
//bmp[y][x]
char bmp[251][251];

void swap_if_bigger(int& x, int& y)
{
    if(x>y)
        swap(x, y);
}

//I M N  Creates a new table M×N. All the pixels are colored in white (O)
void create()
{
    scanf("%d %d", &m, &n);
    memset(bmp, 'O', sizeof(bmp));
}

//C  Clears the table. The size remains the same. All the pixels became white (O).
void clear()
{
    memset(bmp, 'O', sizeof(bmp));
}

//L X Y C    Colors the pixel with coordinates (X,Y) in colour C.
void draw_pixel()
{
    int x,y;
    char color;
    scanf("%d %d %c", &x, &y, &color);
    bmp[y][x]=color;
}

//V X Y1 Y2 C    Draws the vertical segment in the column X between the rows Y1 and Y2 inclusive in colour C.
void draw_ver_seg()
{
    int x, y1, y2;
    char c;
    scanf("%d %d %d %c", &x, &y1, &y2, &c);
    swap_if_bigger(y1, y2);
    for(int y=y1;y<=y2;y++)
    {
        bmp[y][x]=c;
    }
}

//H X1 X2 Y C    Draws the horizontal segment in the row Y between the columns X1 and X2 inclusive in colour C.
void draw_hor_seg()
{
    int x1, x2, y;
    char c;
    scanf("%d %d %d %c", &x1, &x2, &y, &c);
    swap_if_bigger(x1, x2);
    for(int x=x1;x<=x2;x++)
    {
        bmp[y][x]=c;
    }
}

//K X1 Y1 X2 Y2 C    Draws the filled rectangle in colour C. (X1,Y1) is the upper left corner, (X2,Y2) is the lower right corner of the rectangle.
void draw_rect()
{
    int x1, y1, x2, y2;
    char c;
    scanf("%d %d %d %d %c", &x1, &y1, &x2, &y2, &c);
    swap_if_bigger(x1, x2);
    swap_if_bigger(y1, y2);
    for(int x=x1;x<=x2;x++)
        for(int y=y1;y<=y2;y++)
        {
            bmp[y][x]=c;
        }
}

//F X Y C    Fills the region with the colour C. The region R to be filled is defined as follows. The pixel (X,Y) belongs to this region. The other pixel belongs to the region R if and only if it has the same colour as pixel (X,Y) and a common side with any pixel which belongs to this region.
void _fill_region(int x, int y, char c)
{
    char old_color=bmp[y][x];
    if(old_color==c)
        return;
    bmp[y][x]=c;
    static int direction[4][2]={
        {-1, 0},
        {1, 0},
        {0, -1},
        {0, 1},
    };

    for(int i=0;i<4;i++)
    {
        int nx=x+direction[i][0];
        int ny=y+direction[i][1];

        if(nx<1 || nx>m || ny<1 || ny>n)
            continue;

        if(bmp[ny][nx]==old_color)
        {
           // cout<<nx<<" "<<ny<<endl;
            _fill_region(nx, ny, c);
        }
    }

}

void fill_region()
{
    int x,y;
    char c;
    scanf("%d %d %c", &x, &y, &c);
    _fill_region(x, y, c);
}

//S Name     Writes the picture in the file Name.
void save()
{
    string filename;
    cin>>filename;
    cout<<filename<<endl;
    for(int y=1;y<=n;y++)
    {
        for(int x=1;x<=m;x++)
        {
            cout<<bmp[y][x];
        }
        cout<<endl;
    }
}

 

int main()
{
    char cmd;
    char line[256];
    while(cin>>cmd)
    {
        if(cmd=='X')
            break;
        switch(cmd)
        {
            case 'I':
                create();
                break;
            case 'C':
                clear();
                break;
            case 'L':
                draw_pixel();
                break;
            case 'V':
                draw_ver_seg();
                break;
            case 'H':
                draw_hor_seg();
                break;
            case 'K':
                draw_rect();
                break;
            case 'F':
                fill_region();
                break;
            case 'S':
                save();
                break;
            default:
                gets(line);
                continue;
        }

    }

    return 0;
}

PC/UVa 题号: 110105/10267 Graphical Editor (图形化编辑器)题解的更多相关文章

  1. PC/UVa 题号: 110106/10033 Interpreter (解释器)题解 c语言版

    , '\n'); #include<cstdio> #include<iostream> #include<string> #include<algorith ...

  2. PC/UVa 题号: 110104/706 LC-Display (液晶显示屏)题解

    #include <string> #include <iostream> #include <cstring> #include <algorithm> ...

  3. PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

  4. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem E: Graphical Editor(模拟控制台命令形式修改图形)

    Problem E: Graphical Editor Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 2  Solved: 2[Submit][Statu ...

  5. ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor

    Description Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way ...

  6. uva题库爬取

    每次进uva都慢的要死,而且一步一步找到自己的那个题目简直要命. 于是,我想到做一个爬取uva题库,记录一下其中遇到的问题. 1.uva题目的链接是一个外部的,想要获取https资源,会报出SNIMi ...

  7. Asp.Net Core 使用Monaco Editor 实现代码编辑器

    在项目中经常有代码在线编辑的需求,比如修改基于Xml的配置文件,编辑Json格式的测试数据等.我们可以使用微软开源的在线代码编辑器Monaco Editor实现这些功能.Monaco Editor是著 ...

  8. 天大acm 题号1002 Maya Calendar

    Description 上周末,M.A. Ya教授对古老的玛雅有了一个重大发现.从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法.这 个Haab历 ...

  9. The Trip PC/UVa IDs: 110103/10137, Popularity: B, Success rate: average Level: 1

    #include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...

随机推荐

  1. (5)Quartz学习

    原文:http://blog.csdn.net/zxl315/article/details/10879927 介绍Quartz Quartz是一个开源的任务调度系统,它能用来调度很多任务的执行. 运 ...

  2. 【Unity3D】枪战游戏—弹孔设置

    以子弹为原点,发射射线,如果射线检测到障碍物,则返回射线与障碍物的碰撞点 在该点处实例化出弹孔贴图 void Update () { transform.Translate (Vector3.forw ...

  3. POJ 1716 Integer Intervals

    题意:给出一些区间,求一个集合的长度要求每个区间里都至少有两个集合里的数. 解法:贪心或者差分约束.贪心的思路很简单,只要将区间按右边界排序,如果集合里最后两个元素都不在当前区间内,就把这个区间内的最 ...

  4. hdu 2459 (后缀数组+RMQ)

    题意:让你求一个串中连续重复次数最多的串(不重叠),如果重复的次数一样多的话就输出字典序小的那一串. 分析:有一道比这个简单一些的题spoj 687, 假设一个长度为l的子串重复出现两次,那么它必然会 ...

  5. Java Sleep() 与 Wait()的机制原理与区别

    一.概念.原理.区别    Java中的多线程是一种抢占式的机制而不是分时机制.线程主要有以下几种状态:可运行,运行,阻塞,死亡.抢占式机制指的是有多个线程处于可运行状态,但是只有一个线程在运行. 回 ...

  6. Storm实战常见问题及解决方案

    该文档为实实在在的原创文档,转载请注明: http://blog.sina.com.cn/s/blog_8c243ea30101k0k1.html 类型 详细 备注 该文档是群里几个朋友在storm实 ...

  7. <转>ERP的测试用例模板

    1页面部分(1) 页面清单是否完整(是否已经将所需要的页面全部都列出来了)(2) 页面是否显示(在不同分辨率下页面是否存在,在不同浏览器版本中页面是是否显示)(3) 页面在窗口中的显示是否正确.美观( ...

  8. 【windows核心编程】IO完成端口(IOCP)复制文件小例

    1.演示内容 文件复制 2.提要 复制大文件时,使用FILE_FLAG_NO_BUFFERING标志 同时需要注意: 读写文件的偏移地址为 磁盘扇区 的整数倍 读写文件的字节数为 磁盘扇区 的整数倍 ...

  9. MDI端口和MDIX端口是什么? 又有什么作用?

    是网线的标准A类接法和B类接法.也就是人们通常所说的交叉网线和直联网线.直联网线就是 白黄 黄 白绿 蓝 白兰 绿 白棕 棕 另一端同样如此.交叉网线就是 另一端的1和3,2和6对调.这样就成了交叉网 ...

  10. LyX转Word

    写毕业论文是一件非常繁锁的事情,一大堆的图片.公式都要往上贴,有时弄不好就把编号搞错了,有时可能没注意,一不小心字体格式.版面格式又全乱了.怎么办?--其实这只是在word环境下才会有的烦恼. 对于w ...