UVA 10267
来源:互联网 发布:农村淘宝是什么快递 编辑:程序博客网 时间:2024/06/05 17:29
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:
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 6L 2 3 AS one.bmpG 2 3 JF 3 3 JV 2 3 4 WH 3 4 2 ZS two.bmpX
Sample Output
one.bmpOOOOOOOOOOOAOOOOOOOOOOOOOOOOOOtwo.bmpJJJJJJJZZJJWJJJJWJJJJJJJJJJJJJ
这道题是一道极好的小模拟 , 至少我写得很爽 , 虽然WA了两次
主要trick有一下几个 :首先x1 , x2 --- 不确定大小关系;其次这题用Y表示横坐标,X表示纵坐标 ,我就WA在这儿了。
其中还有个小递归 , 要想一下 ,其他没啥了
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>char a[255][255];char G;char s[20];int vis[255][255];int m , n;void find(int i , int j , char G){ if(vis[i][j]||i < 1 || j < 1||i > m ||j > n)return ; vis[i][j] = 1; if(a[i - 1][j] == a[i][j])find(i - 1 , j , G); if(a[i + 1][j] == a[i][j])find(i + 1 , j , G); if(a[i][j - 1] == a[i][j])find(i , j - 1 , G); if(a[i][j + 1] == a[i][j])find(i , j + 1 , G); a[i][j] = G;}using namespace std;int main(){ char c ; int x1 , y1 , x2 , y2 , X , Y; //freopen("in.txt" , "r" , stdin); while(~scanf("%c",&c)) { if(c == 'X')break; switch(c) { case 'I': cin >> n >> m; for(int i = 1 ; i <= m ; i++) { for(int j = 1 ; j <= n ; j++) { a[i][j] = 'O'; } } break; case 'C': for(int i = 1 ; i <= m ; i++) { for(int j = 1 ; j <= n ; j++) { a[i][j] = 'O'; } } break; case 'L': cin >> y1 >> x1 >> G; a[x1][y1] = G; break; case 'V': cin >> Y >> x1 >> x2 >> G; if(x1 > x2)swap(x1 , x2); for(int i = x1 ; i <= x2 ; i++) { a[i][Y] = G; } break; case 'H': cin >> y1 >> y2 >> X >> G; if(y1 > y2)swap(y1 , y2); for(int i = y1 ; i <= y2 ; i++) { a[X][i] = G; } break; case 'K': cin >> y1 >> x1 >> y2 >> x2 >> G; if(x1 > x2)swap(x1 , x2); if(y1 > y2)swap(y1 , y2); for(int i = x1 ; i <= x2 ; i++) { for(int j = y1 ; j <= y2 ; j++) { a[i][j] = G; } } break; case 'F': cin >> Y >> X >> G; memset(vis , 0 , sizeof(vis)); find(X , Y , G); break; case 'S': cin >> s; cout << s << endl; for(int i = 1 ; i <= m ; i ++) { for(int j = 1 ; j <= n ; j++) { cout << a[i][j]; } cout << endl; } break; default : continue; } } return 0;}
- UVA 10267
- Uva 10267
- UVa 10267
- UVA 10267
- uva-10267 - Graphical Editor
- UVa 10267-Graphical Editor
- uva 10267 Graphical Editor
- UVA 10267 - Graphical Editor
- UVa 10267 Graphical Editor
- UVa 10267 Graphical Editor
- UVa 10267 Graphical Editor
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- oooooooookkkkkkkkkkkkkkkkkkkkkkkkk
- 汇编程序
- Android应用程序的生命周期
- plsql插入.dmp文件
- 达夫设备
- UVA 10267
- Volatile相关知识
- 斐波纳契数列
- 四月不做论文五月徒悲伤 (三) 第三章
- error LNK2019: 无法解析的外部符号(编程解决方法)(改)
- 最长回文字串
- 虚拟继承内存剖析
- Qt下打印文档,请考虑QPainter(写给我这样的新手)
- android中的AppWidget