PC/UVA 110105/10267
|
//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 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. InputThe 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. The editor accepts the following commands:
OutputOn 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 InputI 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 Outputone.bmp OOOOO OOOOO OAOOO OOOOO OOOOO OOOOO two.bmp JJJJJ JJZZJ JWJJJ JWJJJ JJJJJ JJJJJ |