Problem E: Graphical Editor

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 2  Solved: 2
[Submit][Status][Web Board]

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 (XY) in color (C).
V X Y1 Y2 C Draw a vertical segment of color (C) in columnX, 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 X2inclusive.
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 (XY) belongs to R. Any other pixel which is the same color as pixel(XY) 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

HINT


  模拟题。模拟的是控制台输命令的形式操作图片。

  用switch()语句分别定义每一个命令。

  需要注意的是F(填充命令),它的意思是将(X,Y)点的像素颜色相同的区域全部填充为C颜色。

  其中样例输入里面的G命令是错误命令,意思是提示你遇到错误命令的时候不做处理。

  另外,S NAME命令里提到了 MSDOS 8.3短文件名 格式输出,它的意思是:

    8代表主文件名长度不超过8个字符。

    3代表后缀名长度不超过3个字符。

    且文件名内不能包括空格。

My code:

 #include <iostream>
#include <string.h>
using namespace std;
char a[][];
int main()
{
//command
char com;
//C
int M,N;
//L
int lx,ly;
char lc;
//V
int vx,vy1,vy2;
char vc;
//H
int hx1,hx2,hy;
char hc;
//K
int kx1,kx2,ky1,ky2;
char kc;
//F
int fx,fy;
char fc,cc;
//S
string l;
while(cin>>com){
if(com=='X') //遇到X退出
break;
if(com!='I' && com!='C' && com!='L' && com!='V' && com!='H' && com!='K' && com!='F' && com!='S'){ //其他命令退出
getline(cin,l);
continue;
}
switch(com){
case 'I':
cin>>M>>N;
for(int i=;i<=N;i++) //创建M*N的空白(O)画板
for(int j=;j<=M;j++){
a[i][j]='O';
}
break;
//默认全部为O
case 'C':
//清空所有色彩为O
for(int i=;i<=N;i++) //清空画板
for(int j=;j<=M;j++){
a[i][j]='O';
}
case 'L':
cin>>lx>>ly>>lc;
a[ly][lx]=lc; //将lx,ly位置的颜色填充为lc
break;
case 'V':
cin>>vx>>vy1>>vy2>>vc;
for(int i=vy1;i<=vy2;i++)
a[i][vx]=vc; //将x列vy1到vy2的像素颜色填充为vc
break;
case 'H':
cin>>hx1>>hx2>>hy>>hc;
for(int i=hx1;i<=hx2;i++)
a[hy][i]=hc; //将y行vx1到vx2的像素颜色填充为hc
break;
case 'K':
cin>>kx1>>kx2>>ky1>>ky2>>kc;
for(int i=ky1;i<=ky2;i++) //填充kx1,kx2,ky1,ky2区域为kc颜色
for(int j=kx1;j<=kx2;j++){
a[i][j]=kc;
}
break;
case 'F':
cin>>fx>>fy>>fc;
cc=a[fy][fx];
for(int i=;i<=N;i++) //填充画板与x,y点颜色相同的区域颜色为C
for(int j=;j<=M;j++){
if(a[i][j]==cc)
a[i][j]=fc;
}
break;
case 'S':
cin>>l;
cout<<l<<endl; //先输出文件名
for(int i=;i<=N;i++){ //显示
for(int j=;j<=M;j++)
cout<<a[i][j];
cout<<endl;
}
break;
}
}
return ;
} /**************************************************************
Problem: 1498
User: freecode
Language: C++
Result: Accepted
Time:0 ms
Memory:1328 kb
****************************************************************/

Freecode : www.cnblogs.com/yym2013

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

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

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

  2. Windows核心编程第一章.错误处理

    Windows核心编程第一章,错误处理. 一丶错误处理 1.核心编程学习总结 不管是做逆向,开始做开发.在Windows下.你都需要看一下核心编程这本书.这本书确实写得很好.所以自己在学习这本书的同时 ...

  3. .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来,首先,请允许我长吸一口气!真没想到一份来自28岁老程序员 ...

  4. net core体系-web应用程序-4asp.net core2.0 项目实战(CMS)-第一章 入门篇-开篇及总体规划

    .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划   原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来 ...

  5. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem D: LC-Display(模拟计算器显示数字)

    Problem D: LC-Display Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 14  Solved: 3[Submit][Status][We ...

  6. Java 面向对象编程——第一章 初识Java

      第一章    初识Java 1.  什么是Java? Java是一种简单的.面向对象的.分布式的.解释的.安全的.可移植的.性能优异的多线程语言.它以其强安全性.平台无关性.硬件结构无关性.语言简 ...

  7. Java学习笔记 第一章 入门<转>

    第一章 JAVA入门 一.基础常识 1.软件开发 什么是软件? 软件:一系列按照特定顺序组织的计算机数据和指令的集合 系统软件:DOS,Windows,Linux 应用软件:扫雷.QQ.迅雷 什么是开 ...

  8. windows核心编程-第一章 对程序错误的处理

    第一章-对程序错误的处理 在开始介绍Microsoft Windows 的特性之前,必须首先了解 Wi n d o w s的各个函数是如何进行错误处理的. 当调用一个Wi n d o w s函数时,它 ...

  9. UNIX环境高级编程--第一章 UNIX基础知识

    第一章 UNIX基础知识 1.2 UNIX体系结构   从严格意义上说,可将操作系统定义为一种软件,它控制计算机硬件资源,提供程序运行环境.我们将这种软件称为内核(kernel),因为 它相对较小,且 ...

随机推荐

  1. input file美化

    <style> a{display:inline-block; width:100px; height:40px; position:relative; overflow:hidden;} ...

  2. bootshrap会改变IE浏览器滚动条样式

    在某个小网站的开发中 客户一直抱怨在IE11中网页右边滚动条不一样 后来发现在IE11中,有2个页面滚动条会自动隐藏,一开始以为是浏览器默认行为,改了overflow:scroll后也没有用.仔细观察 ...

  3. QQ微信与智能家电连接一起 小马哥"连接一切"野心凸显

    昨日,彭博社对于海南举行的腾讯全球合作伙伴大会进行了报道,文章指出腾讯公司正在发力移动端,将其即时通讯工具QQ和微信与烤箱.电视.空调等其他家电连接在一起.小马哥"连接一切"的野心 ...

  4. 黑色30s高并发IIS设置

    在这篇博文中,我们抛开对阿里云的怀疑,完全从ASP.NET的角度进行分析,看能不能找到针对问题现象的更合理的解释. “黑色30秒”问题现象的主要特征是:排队的请求(Requests Queued)突增 ...

  5. springmvc 项目完整示例06 日志–log4j 参数详细解析 log4j如何配置

    Log4j由三个重要的组件构成: 日志信息的优先级 日志信息的输出目的地 日志信息的输出格式 日志信息的优先级从高到低有ERROR.WARN. INFO.DEBUG,分别用来指定这条日志信息的重要程度 ...

  6. IOS AFNetworking

    http://www.coneboy.com/?p=716 AFNetworking 使用总结 (用法+JSON解析) 2013 年 4 月 11 日  No comments Article 这几天 ...

  7. mysql中binary相加的问题

    我在mysql中有这样一段代码 SQL code   ? 1 2 3 4 5 6 7 8 declare @byte1 binary(1) declare @byte2 binary(1) decla ...

  8. 【SpringMVC】SpringMVC系列13之关于 mvc:annotation-driven

    13.关于 mvc:annotation-driven 13.1.概述      会自动注册RequestMappingHandlerMapping.RequestMappingHandlerAdap ...

  9. 尖刀出鞘的display常用属性及css盒模型深入研究

    一:diplay:inline-block 含义:指元素创建了一个行级的块级元素,该元素内部(内容)被格式化成一个块级元素,同时元素本身则被格式化成一个行内元素.更简单的说就是说inline-bloc ...

  10. 67. 总结篇:面试中随机数"等概率"vs"不等概率"生成问题[random generator with equal or unequal probability]

    [本文链接] http://www.cnblogs.com/hellogiser/p/random-generator-with-equal-or-unequal-probability.html 1 ...