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的更多相关文章

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

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

  2. ACM YTU 挑战编程 字符串 Problem A: WERTYU

    Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...

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

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

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

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

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

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

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

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

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

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

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

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

  9. 读高性能JavaScript编程 第一章

    草草的看完第一章,虽然看的是译文也是感觉涨姿势了, 我来总结一下: 由于 大多数浏览器都是 single process 处理 ui updatas and js execute 于是产生问题: js ...

随机推荐

  1. Android图形系统之Surface、SurfaceView、SurfaceHolder及SurfaceHolder.Callback开发实例

    原文:Android图形系统之Surface.SurfaceView.SurfaceHolder及SurfaceHolder.Callback之间的联系 Surface是原始图像缓冲区(raw buf ...

  2. JQ绑定事件(1.9已经废除了live()等绑定事件方法,on()方法是官方推荐的绑定事件的一个方法)

    本文来源:http://www.cnblogs.com/leejersey/p/3545372.html jQuery on()方法是官方推荐的绑定事件的一个方法. $(selector).on(ev ...

  3. 解决Scrapy抓取中文结果保存为文件时的编码问题

    import json import codecs # Define your item pipelines here # # Don't forget to add your pipeline to ...

  4. LR(1)表驱动语法分析程序

    /* * LR(1) 语法分析 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #inc ...

  5. Tornado自定义分布式session框架

    一.session框架处理请求执行的流程: 1.服务器端生成随机的cookie字符串 2.浏览器发送请求,服务器将cookie返回给浏览器. 3.服务器在生成一个字典.字典的key为cookie,va ...

  6. oc学习之路-----搞死指针之内存存储int类型

    关于每个数据类型个字节在内存中的存储地址(以int为例) 先上图 如题,为什么说好的*p = &c是1啊,为什么是513呢,一开始,我也觉得挺惊讶的,后面听老师分析了一下才知道怎么回事,但是还 ...

  7. jquery获取节点的时候获取包含自己在内的HTML标签

    jquery获取某个标签的html()方法的时候总是只能获取内部的 如果获取包含自身的HTML代码呢? 用.prop("outerHTML")方法获取 <div id=&qu ...

  8. runnable:在线IDE+代码片段分享

    在我之前的博客20个最好的在线IDE中列举过很多在线IDE,可以很方便的在云端执行代码,这样在你手头没有编译器时想试个小程序会非常有用. 今天介绍的这个网站runnable把在线IDE和代码片段结合了 ...

  9. Xilinx ISE14.7 安装教程(转)

    文章来源http://blog.chinaaet.com/crazybird/p/39693 作者:crazybird **************************************** ...

  10. NPOI组件集锦

    关于NPOI不错的介绍:http://www.cnblogs.com/restran/p/3889479.html http://www.cnblogs.com/Irving/archive/2012 ...