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:

  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. char a[][];
  5. int main()
  6. {
  7. //command
  8. char com;
  9. //C
  10. int M,N;
  11. //L
  12. int lx,ly;
  13. char lc;
  14. //V
  15. int vx,vy1,vy2;
  16. char vc;
  17. //H
  18. int hx1,hx2,hy;
  19. char hc;
  20. //K
  21. int kx1,kx2,ky1,ky2;
  22. char kc;
  23. //F
  24. int fx,fy;
  25. char fc,cc;
  26. //S
  27. string l;
  28. while(cin>>com){
  29. if(com=='X') //遇到X退出
  30. break;
  31. if(com!='I' && com!='C' && com!='L' && com!='V' && com!='H' && com!='K' && com!='F' && com!='S'){ //其他命令退出
  32. getline(cin,l);
  33. continue;
  34. }
  35. switch(com){
  36. case 'I':
  37. cin>>M>>N;
  38. for(int i=;i<=N;i++) //创建M*N的空白(O)画板
  39. for(int j=;j<=M;j++){
  40. a[i][j]='O';
  41. }
  42. break;
  43. //默认全部为O
  44. case 'C':
  45. //清空所有色彩为O
  46. for(int i=;i<=N;i++) //清空画板
  47. for(int j=;j<=M;j++){
  48. a[i][j]='O';
  49. }
  50. case 'L':
  51. cin>>lx>>ly>>lc;
  52. a[ly][lx]=lc; //将lx,ly位置的颜色填充为lc
  53. break;
  54. case 'V':
  55. cin>>vx>>vy1>>vy2>>vc;
  56. for(int i=vy1;i<=vy2;i++)
  57. a[i][vx]=vc; //将x列vy1到vy2的像素颜色填充为vc
  58. break;
  59. case 'H':
  60. cin>>hx1>>hx2>>hy>>hc;
  61. for(int i=hx1;i<=hx2;i++)
  62. a[hy][i]=hc; //将y行vx1到vx2的像素颜色填充为hc
  63. break;
  64. case 'K':
  65. cin>>kx1>>kx2>>ky1>>ky2>>kc;
  66. for(int i=ky1;i<=ky2;i++) //填充kx1,kx2,ky1,ky2区域为kc颜色
  67. for(int j=kx1;j<=kx2;j++){
  68. a[i][j]=kc;
  69. }
  70. break;
  71. case 'F':
  72. cin>>fx>>fy>>fc;
  73. cc=a[fy][fx];
  74. for(int i=;i<=N;i++) //填充画板与x,y点颜色相同的区域颜色为C
  75. for(int j=;j<=M;j++){
  76. if(a[i][j]==cc)
  77. a[i][j]=fc;
  78. }
  79. break;
  80. case 'S':
  81. cin>>l;
  82. cout<<l<<endl; //先输出文件名
  83. for(int i=;i<=N;i++){ //显示
  84. for(int j=;j<=M;j++)
  85. cout<<a[i][j];
  86. cout<<endl;
  87. }
  88. break;
  89. }
  90. }
  91. return ;
  92. }
  93.  
  94. /**************************************************************
  95. Problem: 1498
  96. User: freecode
  97. Language: C++
  98. Result: Accepted
  99. Time:0 ms
  100. Memory:1328 kb
  101. ****************************************************************/

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. [LeetCode] Best Time to Buy and Sell Stock III

    将Best Time to Buy and Sell Stock的如下思路用到此题目 思路1:第i天买入,能赚到的最大利润是多少呢?就是i + 1 ~ n天中最大的股价减去第i天的. 思路2:第i天买 ...

  2. 常用webshell提权方法总结

    pcAnywhere提权:1.利用pcAnywhere提权,前提条件是pcAnywhere默认安装到默认路径,以及它的目录安全权限有users权限,如果管理员删除了users和power users用 ...

  3. C++ 迭代器 基础介绍

    C++ 迭代器 基础介绍 迭代器提供对一个容器中的对象的访问方法,并且定义了容器中对象的范围.迭代器就如同一个指针.事实上,C++的指针也是一种迭代器.但是,迭代器不仅仅是指针,因此你不能认为他们一定 ...

  4. Eclipse启动Tomcat,45S超时问题解决

    在Eclipse中启动Tomcat服务器时,经常由于系统初始化项目多,导致出现45秒超时的Tomcat服务器启动错误.     以前我一般通过找到XML配置文件,将对应Timeout为45的值,修改为 ...

  5. mysql 启动 导入sql文件

    mysql mysqld.exe mysqld.exe 是mysql的服务器进程,只有先启动这个进程才能连接服务器 dos下进入mysql文件目录下的bin目录,输入mysql -u root -p ...

  6. Entity Framework 关系约束配置

    前言 简单的说一下自己的理解,大家应该都很明白ADO.NET,也就是原生态的数据库操作,直接通过拼接SQL语句,表与表之间通过链接(inner join  left join  或者子查询),也就是在 ...

  7. ACM Computer Factory(dinic)

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5596   Accepted: 1 ...

  8. 第19章 使用PXE+Kickstart部署无人值守安装

    章节概述: 本章节将教会您通过PXE+DHCP+TFTP+VSftpd+Kickstart服务程序搭建出无人值守安装系统,从而批量部署客户机系统. 这种系统能够实现自动化运维.避免了重复性劳动,帮助提 ...

  9. unity3d中资源文件从MAX或者MAYA中导出的注意事项

    原地址:http://blog.sina.com.cn/s/blog_6ad33d3501011ekx.html 之前在项目中,没有怎么接触过美术的软件(之前的美术团队很犀利,被他们宠坏了).在自己公 ...

  10. [BZOJ2423][HAOI2010]最长公共子序列

    [BZOJ2423][HAOI2010]最长公共子序列 试题描述 字符序列的子序列是指从给定字符序列中随意地(不一定连续)去掉若干个字符(可能一个也不去掉)后所形成的字符序列.令给定的字符序列X=“x ...