1.6.5 图形化编辑器 Graphical Editor

PC/UVA 110105/10267
本题需要注意的就是,它指的(x,y)是x列y行

//author: CHC
//First Edit Time:	2014-01-12 13:14
//Last Edit Time:	2014-01-12 13:14
//Filename:1.cpp
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
int n,m;
char map[300][300];
int dx[]={ 0,0,1,-1 };
int dy[]={ 1,-1,0,0 };
void dfs(int x,int y,char color,char fill)
{
    if(x<1||x>n||y<1||y>m)return ;
    if(map[x][y]!=color||map[x][y]==fill)return ;
    map[x][y]=fill;
    for(int i=0;i<4;i++)
        dfs(x+dx[i],y+dy[i],color,fill);
}
int main()
{
    char t[1000];
    while(gets(t)!=NULL)
    {
        if(t[0]=='X')break;
        if(t[0]=='I')
        {
            //scanf("%d%d",&m,&n);//m列n行
            sscanf(t,"%*c %d %d",&m,&n);
            memset(map,'O',sizeof(map));
        }
        else if(t[0]=='C')
            memset(map,'O',sizeof(map));
        else if(t[0]=='L')
        {
            int x,y;
            char tx;
            //scanf("%d%d %c",&x,&y,&tx);
            sscanf(t,"%*c %d %d %c",&x,&y,&tx);
            map[y][x]=tx;
        }
        else if(t[0]=='V')
        {
            int x,y1,y2;
            char tx;
            //scanf("%d%d%d %c",&x,&y1,&y2,&tx);
            sscanf(t,"%*c %d %d %d %c",&x,&y1,&y2,&tx);
            if(y1>y2)y1^=y2^=y1^=y2;
            for(int i=y1;i<=y2;i++)
                map[i][x]=tx;
        }
        else if(t[0]=='H')
        {
            int x1,x2,y;
            char tx;
            //scanf("%d%d%d %c",&x1,&x2,&y,&tx);
            sscanf(t,"%*c %d %d %d %c",&x1,&x2,&y,&tx);
            if(x1>x2)x1^=x2^=x1^=x2;
            for(int i=x1;i<=x2;i++)
                map[y][i]=tx;
        }
        else if(t[0]=='K')
        {
            int x1,y1,x2,y2;
            char tx;
            //scanf("%d%d%d%d %c",&x1,&y1,&x2,&y2,&tx);
            sscanf(t,"%*c %d %d %d %d %c",&x1,&y1,&x2,&y2,&tx);
            for(int i=y1;i<=y2;i++)
            for(int j=x1;j<=x2;j++)
                map[i][j]=tx;
        }
        else if(t[0]=='F')
        {
            int x,y;
            char tx;
            //scanf("%d%d %c",&x,&y,&tx);
            sscanf(t,"%*c %d %d %c",&x,&y,&tx);
            dfs(y,x,map[y][x],tx);
        }
        else if(t[0]=='S')
        {
            char name[1000];
            //scanf(" %s",name);
            sscanf(t,"%*c %s",name);
            printf("%s\n",name);
            for(int i=1;i<=n;i++,puts(""))
            for(int j=1;j<=m;j++)
                putchar(map[i][j]);
            /*
            for(int i=1;i<=m;i++,puts(""))
            for(int j=1;j<=n;j++)
                putchar(map[i][j]);
                */
        }
    }
    return 0;
}



Graphical Editor

 

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 1$ \le$MN$ \le$250. The origin sits in the upper-left corner of the table. Colors are specified by capital letters.

The editor accepts the following commands:

I M NCreate a new M x N image with all pixels initially colored white (O).
CClear the table by setting all pixels white (O). The size remains unchanged.
L X Y CColors the pixel (XY) in color (C).
V X Y1 Y2 CDraw a vertical segment of color (C) in column X, between the rows Y1 andY2 inclusive.
H X1 X2 Y CDraw a horizontal segment of color (C) in the row Y, between the columns X1 and X2 inclusive.
K X1 Y1 X2 Y2 CDraw a filled rectangle of color C, where (X1, Y1) is the upper-left and(X2, Y2) the lower right corner.
F X Y CFill 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 (X,Y) and shares a common side with any pixel in R also belongs to this region.
S NameWrite the file name in MSDOS 8.3 format followed by the contents of the current image.
XTerminate 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值