ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor
Description
Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way that text editors allow us to modify documents. Images are represented as an M x N array of pixels, where each pixel has a given color. Your task is to write a program which
simulates a simple interactive graphical editor.
Input
The input consists of a sequence of editor commands, one per line. Each command is represented by one capital letter placed as the first character of the line. If the command needs parameters, they will be given on the same line separated by spaces. Pixel coordinates
are represented by two integers, a column number between 1...M and a row number between 1...N, where 1M, N250. The origin sits in the upper-left corner of the table. Colors are specified by capital letters.
I M N Create a new M x N image with all pixels initially colored white (O).
C Clear the table by setting all pixels white (O). The size remains unchanged.
L X Y C Colors the pixel (X, Y) in color (C).
V X Y1 Y2 C Draw a vertical segment of color (C) in column X, between the rows Y1 and Y2 inclusive.
H X1 X2 Y C Draw a horizontal segment of color (C) in the row Y, between the columns X1 and X2 inclusive.
K X1 Y1 X2 Y2 C Draw a filled rectangle of color C, where (X1, Y1) is the upper-left and (X2, Y2) the lower right corner.
F X Y C Fill the region R with the color C, where R is defined as follows. Pixel (X, Y) belongs to R. Any other pixel which is the same color as pixel (X, Y) and shares a common side with any pixel in R also belongs to this region.
S Name Write the file name in MSDOS 8.3 format followed by the contents of the current image.
X Terminate the session.
Output
On every command S NAME, print the filename NAME and contents of the current image. Each row is represented by the color contents of each pixel. See the sample output. Ignore the entire line of any command defined by a character other than I, C, L, V, H, K,
F, S, or X, and pass on to the next command. In case of other errors, the program behavior is unpredictable.
Sample Input
I 5 6
L 2 3 A
S one.bmp
G 2 3 J
F 3 3 J
V 2 3 4 W
H 3 4 2 Z
S two.bmp
X
Sample Output
one.bmp
OOOOO
OOOOO
OAOOO
OOOOO
OOOOO
OOOOO
two.bmp
JJJJJ
JJZZJ
JWJJJ
JWJJJ
JJJJJ
JJJJJ
#include <iostream>
#include<string>
using namespace std;
char str[255][255];
string name;
void print(int N,int M)
{
//cout<<name<<endl;
for(int i = 1;i<=N;i++)
{
for(int j = 1;j<=M;j++)
{
cout<<str[i][j];
}
cout<<endl;
}
for(int i = 1;i<=N;i++)
{
for(int j = 1;j<=M;j++)
{
str[i][j] = 'O';
}
}
}
int main()
{
char ch;
int X,Y,M,N;
int X0 ,Y1,Y2 ,X1,X2,Y0;
int x1,y1,x2,y2;
int XF,YF;
char CL,CV,CH,CK,CF;
char CF_0; while(cin>>ch&&ch!='X')
{ switch(ch)
{
case 'I':
cin>>M>>N;
for(int i = 1;i<=N;i++)
{
for(int j = 1;j<=M;j++)
{
str[i][j] = 'O';
}
}
break;
case 'C':
for(int i = 1;i<=M;i++)
{
for(int j = 1;j<=N;j++)
{
str[i][j] = 'O';
}
}
break;
case 'L':
cin>>X>>Y>>CL;
str[Y][X] = CL;
break;
case 'V':
cin>>X0>>Y1>>Y2>>CV;
for(int i = Y1;i<=Y2;i++)
{
str[i][X0] = CV;
}
break;
case 'H':
cin>>X1>>X2>>Y0>>CH;
for(int i = X1;i<=X2;i++)
{
str[Y0][i] = CH;
}
break;
case 'K':
cin>>x1>>y1>>x2>>y2>>CK;
for(int i = y1;i<=y2;i++)
{
for(int j = x1;j<=x2;j++)
str[i][j] = CK;
}
break;
case 'F':
cin>>XF>>YF>>CF;
CF_0=str[YF][XF];
for(int i = 1;i<=N;i++)
{
for(int j = 1;j<=M;j++)
{
if(str[i][j]==CF_0)
str[i][j] = CF;
}
}
break;
case 'S':
cin>>name;
cout<<name<<endl;
print(N,M);
default:
break;
}
} return 0;
}这道题大概看懂意思后也就不难了,我觉得主要考察的应该是switch的流程控制吧。
//看题要仔细,题中是英文字母‘O’,而不是数字‘0’,我在这WA了好几次……
ACM YTU 《挑战编程》第一章 入门 Problem E: Graphical Editor的更多相关文章
- 烟大 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 A: WERTYU
Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...
- Windows核心编程第一章.错误处理
Windows核心编程第一章,错误处理. 一丶错误处理 1.核心编程学习总结 不管是做逆向,开始做开发.在Windows下.你都需要看一下核心编程这本书.这本书确实写得很好.所以自己在学习这本书的同时 ...
- .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划
作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来,首先,请允许我长吸一口气!真没想到一份来自28岁老程序员 ...
- net core体系-web应用程序-4asp.net core2.0 项目实战(CMS)-第一章 入门篇-开篇及总体规划
.NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来 ...
- Java学习笔记 第一章 入门<转>
第一章 JAVA入门 一.基础常识 1.软件开发 什么是软件? 软件:一系列按照特定顺序组织的计算机数据和指令的集合 系统软件:DOS,Windows,Linux 应用软件:扫雷.QQ.迅雷 什么是开 ...
- Java 面向对象编程——第一章 初识Java
第一章 初识Java 1. 什么是Java? Java是一种简单的.面向对象的.分布式的.解释的.安全的.可移植的.性能优异的多线程语言.它以其强安全性.平台无关性.硬件结构无关性.语言简 ...
- UNIX环境高级编程--第一章 UNIX基础知识
第一章 UNIX基础知识 1.2 UNIX体系结构 从严格意义上说,可将操作系统定义为一种软件,它控制计算机硬件资源,提供程序运行环境.我们将这种软件称为内核(kernel),因为 它相对较小,且 ...
- 读高性能JavaScript编程 第一章
草草的看完第一章,虽然看的是译文也是感觉涨姿势了, 我来总结一下: 由于 大多数浏览器都是 single process 处理 ui updatas and js execute 于是产生问题: js ...
随机推荐
- linux下用Apache一个IP多个网站多域名配置方法
如有两个域名,分别是desk.xker.com和tool.xker.com,需把这两个域名都绑定到IP是219.13.34.32的服务器上 1.首先需在域名供应商管理页面指定域名和IP的对应关系 2. ...
- 玩玩Hibernate(二)hibernate-spider爬虫~~
新建一个hSpider的工程,引入前面已经建立的lib 并为其建立一个hibernate.cfg.xml的映射文件 <?xml version='1.0' encoding='utf-8'?&g ...
- dnspod-sr内网轻量级DNS首选方案 - 运维生存时间
dnspod-sr内网轻量级DNS首选方案 - 运维生存时间 undefined
- weekend110(Hadoop)的 第四天笔记
(2015年1月18日) 课程目录 01-复习 02-hadoop中的序列化机制 03-流量求和mr程序开发 04-hadoop的自定义排序实现 05-mr程序中自定义分组的实现 06-shuffle ...
- MongoDB log4j 日志整合
在分布式系统当中,这些服务可能分别部署在不同的服务器上,并且有各自的日志输出.为了方便对这些日志进行统一管理和分析.我们可以将日志统一输出到指定的数据库系统中,而再由日志分析系统去管理.而这个储存日志 ...
- zookeeper与activemq最新存储replicatedLevelDB整合
测试环境:三台VM虚拟机centos6.4 64位 mini版,IP分别为192.168.1.191/192/193. 测试目的:测试activemq的failover以及与zookeeper的整合 ...
- 关于Ajax&初见Ajax
Ajax实现的效果 究竟Ajax能实现什么功能呢?今天下午学习了一下Ajax,现在跟大家分享一下我的学习心得.Ajax是什么?工作机制又是什么?可能不大准确,只是我个人看了视频学习后的一点点看法. A ...
- SVN安装手册
转:http://www.cnblogs.com/newsea/archive/2012/04/28/2474818.html 常用工具2012-04-04 21:24 by ...
- android79 Fragment生命周期
切换成01时依次调用onCreate,onStart,onResume方法,切换到03的时候01依次onPause,onStop,onDestroy,03依次onCreate,onStart,onRe ...
- Makefile详解--隐含规则
Makefile详解--隐含规则(转) Makefile系列文章,这里有个前辈连续洗了一个系列来介绍,共有26篇博客文章. http://www.cppblog.com/ivenher/archive ...