PC/UVa 题号: 110105/10267 Graphical Editor (图形化编辑器)题解
#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 (图形化编辑器)题解的更多相关文章
- PC/UVa 题号: 110106/10033 Interpreter (解释器)题解 c语言版
, '\n'); #include<cstdio> #include<iostream> #include<string> #include<algorith ...
- PC/UVa 题号: 110104/706 LC-Display (液晶显示屏)题解
#include <string> #include <iostream> #include <cstring> #include <algorithm> ...
- 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 ...
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem E: Graphical Editor(模拟控制台命令形式修改图形)
Problem E: Graphical Editor Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2 Solved: 2[Submit][Statu ...
- ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor
Description Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way ...
- uva题库爬取
每次进uva都慢的要死,而且一步一步找到自己的那个题目简直要命. 于是,我想到做一个爬取uva题库,记录一下其中遇到的问题. 1.uva题目的链接是一个外部的,想要获取https资源,会报出SNIMi ...
- Asp.Net Core 使用Monaco Editor 实现代码编辑器
在项目中经常有代码在线编辑的需求,比如修改基于Xml的配置文件,编辑Json格式的测试数据等.我们可以使用微软开源的在线代码编辑器Monaco Editor实现这些功能.Monaco Editor是著 ...
- 天大acm 题号1002 Maya Calendar
Description 上周末,M.A. Ya教授对古老的玛雅有了一个重大发现.从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法.这 个Haab历 ...
- The Trip PC/UVa IDs: 110103/10137, Popularity: B, Success rate: average Level: 1
#include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...
随机推荐
- vim变ide
如果你稍微写过一点代码,就能知道“集成开发环境”(IDE)是多么的便利.不管是Java.C还是Python,当IDE会帮你检查语法.后台编译,或者自动导入你需要的库时,写代码就变得容易许多.另外,如果 ...
- MySql表中key的区别
我们看到Key那一栏,可能会有4种值,即'啥也没有','PRI','UNI','MUL'1. 如果Key是空的, 那么该列值的可以重复, 表示该列没有索引, 或者是一个非唯一的复合索引的非前导列2. ...
- ECSHOP v2.5数据库字典
ECSHOP v2.5 数据库字典 ECSHOP R&D Team 2007年4月16日 商品相关表 商品分类表 category 此表用来维护商品分类信息 字段名 字段描述 字段类型 默认值 ...
- delete drop truncate
一.相同点 1 truncate.不带where子句的delete.drop都会删除表内的数据2 drop.truncate都是DDL语句(数据定义语言),执行后会自动提交 二.不同点 1trunca ...
- 数组乘积--满足result[i] = input数组中除了input[i]之外所有数的乘积(假设不会溢出
数组乘积(15分) 输入:一个长度为n的整数数组input 输出:一个长度为n的整数数组result,满足result[i] = input数组中除了input[i]之外所有数的乘积(假设不会溢出). ...
- java ant 命令大全
ANT命令总结 1 Ant是什么? Apache Ant 是一个基于 Java的生成工具.生成工具在软件开发中用来将源代码和其他输入文件转换为可执行文件的形式(也有可能转换为可安装的产品映像形式).随 ...
- Centos yum源更新为阿里云
阿里云镜像网址 http://mirrors.aliyun.com/ 更新步骤 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d ...
- 如何用chrome修改js代码,跳过网站等待时间
用chrome修改js代码 By Z.H. Fu 切问录 [maplewizard.github.io](http://maplewizard.github.io ) 网页中大部分的限制都是由js编写 ...
- RabbitMQ三种Exchange模式(fanout,direct,topic)的特性 -摘自网络
RabbitMQ中,所有生产者提交的消息都由Exchange来接受,然后Exchange按照特定的策略转发到Queue进行存储 RabbitMQ提供了四种Exchange:fanout,direct, ...
- 新版本ffmpeg解码非完整H264帧失败
按照ffmpeg/doc/examples/decoding_encoding.c中video_decode_example解码H264,新版本ffmpeg解码非完整H264帧,定量读取数据直接给av ...