24h購物| | PChome| 登入
2012-09-03 20:41:17| 人氣771| 回應0 | 上一篇 | 下一篇

[UVA] 10267 - Graphical Editor

推薦 0 收藏 0 轉貼0 訂閱站台

 Problem E: Graphical Editor 

Problem

The simple graphical editor deals with a rectangular table M×N (1<=M,N<=250). Each pixel of the table has its colour. The picture is formed from this square pixels.

The problem is to write a program, which simulates an interactive work of the graphical editor.

Input

Input consists of the editor commands, one per line. Each command is represented by one Latin capital placed in the very beginning of the line. If the command supposes parameters, all the parameters will be given in the same line separated by space. As the parameters there may be: the coordinates of the pixel - two integers, the first one is the column number and belongs to 1..M, the second one is the row number and belongs to 1..N, the origin is in the upper left corner of the table; the colour - the Latin capital; file name - in MSDOS 8.3 format.

The editor deals with the following commands:

I M N Creates a new table M×N. All the pixels are colored in white (O).
C Clears the table. The size remains the same. All the pixels became white (O).
L X Y C Colors the pixel with coordinates (X,Y) in colour C.
V X Y1 Y2 C Draws the vertical segment in the column X between the rows Y1 and Y2 inclusive in colour C.
H X1 X2 Y C Draws the horizontal segment in the row Y between the columns X1 and X2 inclusive in colour C.
K X1 Y1 X2 Y2 C Draws the filled rectangle in colour C. (X1,Y1) is the upper left corner, (X2,Y2) is the lower right corner of the rectangle.
F X Y C Fills the region with the colour C. The region R to be filled is defined as follows. The pixel (X,Y) belongs to this region. The other pixel belongs to the region R if and only if it has the same colour as pixel (X,Y) and a common side with any pixel which belongs to this region.
S Name Writes the picture in the file Name.
X Terminates the session.

Output

Every time the command S NAME meets, you should output the file name NAME and the current table, row by row. Each row is represented by a pixels' colours series, see the output sample.

Errors

If as a command there will be a character different from I, C, L, V, H, K, F, S, X, the editor should ignore the whole line and pass to the next command.

In case of other errors the program behaviour 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

陷阱遊戲, between 真是害人不淺, 要好好分辦 大小

#include <stdio.h>
#include <string.h>
int main() {
char cmd[100], g[300][300], co, name[100];
int n, m, i, j, x, y, z, w;
while(gets(cmd)) {
if(cmd[0] == 'X') break;
if(cmd[0] == 'I') {
sscanf(cmd+1, "%d %d", &m, &n);
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
g[i][j] = 'O';
} else if(cmd[0] == 'C') {
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
g[i][j] = 'O';
} else if(cmd[0] == 'L') {
sscanf(cmd+1, "%d %d", &y, &x);
co = cmd[strlen(cmd)-1];
g[x-1][y-1] = co;
} else if(cmd[0] == 'V') {
sscanf(cmd+1, "%d %d %d", &x, &y, &z);
if(y > z) {int tmp = y; y = z, z = tmp;}
co = cmd[strlen(cmd)-1];
for(i = y-1; i <= z-1; i++)
g[i][x-1] = co;
} else if(cmd[0] == 'H') {
sscanf(cmd+1, "%d %d %d", &x, &y, &z);
if(x > y) {int tmp = x; x = y, y = tmp;}
co = cmd[strlen(cmd)-1];
for(i = x-1; i <= y-1; i++)
g[z-1][i] = co;
} else if(cmd[0] == 'K') {
sscanf(cmd+1, "%d %d %d %d", &x, &y, &z, &w);
co = cmd[strlen(cmd)-1];
for(i = x-1; i <= z-1; i++)
for(j = y-1; j <= w-1; j++)
g[j][i] = co;
} else if(cmd[0] == 'F') {
sscanf(cmd+1, "%d %d", &y, &x);
co = cmd[strlen(cmd)-1];
char prev = g[x-1][y-1];
int Q[70000][2], qt = 0, used[300][300] = {};
g[x-1][y-1] = co;
Q[0][0] = x-1, Q[0][1] = y-1;
for(i = 0; i <= qt; i++) {
x = Q[i][0], y = Q[i][1];
if(x+1 < n && g[x+1][y] == prev && !used[x+1][y])
Q[++qt][0] = x+1, Q[qt][1] = y, g[x+1][y] = co, used[x+1][y] = 1;

if(x-1 >= 0 && g[x-1][y] == prev && !used[x-1][y])
Q[++qt][0] = x-1, Q[qt][1] = y, g[x-1][y] = co, used[x-1][y] = 1;

if(y+1 < m && g[x][y+1] == prev && !used[x][y+1])
Q[++qt][0] = x, Q[qt][1] = y+1, g[x][y+1] = co, used[x][y+1] = 1;

if(y-1 >= 0 && g[x][y-1] == prev && !used[x][y-1])
Q[++qt][0] = x, Q[qt][1] = y-1, g[x][y-1] = co, used[x][y-1] = 1;

}
} else if(cmd[0] == 'S') {
sscanf(cmd+1, "%s", name);
puts(name);
for(i = 0; i < n; i++, puts(""))
for(j = 0; j < m; j++)
putchar(g[i][j]);
}
}
return 0;
}

台長: Morris
人氣(771) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][模擬、旋轉] 141 - The Spot Game
此分類上一篇:[ACM-ICPC][Asia - Daejeon] 5839 - Block Compaction

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文