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 columnX, 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 X2inclusive. |
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. |
模拟题。模拟的是控制台输命令的形式操作图片。
用switch()语句分别定义每一个命令。
需要注意的是F(填充命令),它的意思是将(X,Y)点的像素颜色相同的区域全部填充为C颜色。
其中样例输入里面的G命令是错误命令,意思是提示你遇到错误命令的时候不做处理。
另外,S NAME命令里提到了 MSDOS 8.3短文件名 格式输出,它的意思是:
8代表主文件名长度不超过8个字符。
3代表后缀名长度不超过3个字符。
且文件名内不能包括空格。
1 #include <iostream> 2 #include <string.h> 3 using namespace std; 4 char a[251][251]; 5 int main() 6 { 7 //command 8 char com; 9 //C 10 int M,N; 11 //L 12 int lx,ly; 13 char lc; 14 //V 15 int vx,vy1,vy2; 16 char vc; 17 //H 18 int hx1,hx2,hy; 19 char hc; 20 //K 21 int kx1,kx2,ky1,ky2; 22 char kc; 23 //F 24 int fx,fy; 25 char fc,cc; 26 //S 27 string l; 28 while(cin>>com){ 29 if(com=='X') //遇到X退出 30 break; 31 if(com!='I' && com!='C' && com!='L' && com!='V' && com!='H' && com!='K' && com!='F' && com!='S'){ //其他命令退出 32 getline(cin,l); 33 continue; 34 } 35 switch(com){ 36 case 'I': 37 cin>>M>>N; 38 for(int i=1;i<=N;i++) //创建M*N的空白(O)画板 39 for(int j=1;j<=M;j++){ 40 a[i][j]='O'; 41 } 42 break; 43 //默认全部为O 44 case 'C': 45 //清空所有色彩为O 46 for(int i=1;i<=N;i++) //清空画板 47 for(int j=1;j<=M;j++){ 48 a[i][j]='O'; 49 } 50 case 'L': 51 cin>>lx>>ly>>lc; 52 a[ly][lx]=lc; //将lx,ly位置的颜色填充为lc 53 break; 54 case 'V': 55 cin>>vx>>vy1>>vy2>>vc; 56 for(int i=vy1;i<=vy2;i++) 57 a[i][vx]=vc; //将x列vy1到vy2的像素颜色填充为vc 58 break; 59 case 'H': 60 cin>>hx1>>hx2>>hy>>hc; 61 for(int i=hx1;i<=hx2;i++) 62 a[hy][i]=hc; //将y行vx1到vx2的像素颜色填充为hc 63 break; 64 case 'K': 65 cin>>kx1>>kx2>>ky1>>ky2>>kc; 66 for(int i=ky1;i<=ky2;i++) //填充kx1,kx2,ky1,ky2区域为kc颜色 67 for(int j=kx1;j<=kx2;j++){ 68 a[i][j]=kc; 69 } 70 break; 71 case 'F': 72 cin>>fx>>fy>>fc; 73 cc=a[fy][fx]; 74 for(int i=1;i<=N;i++) //填充画板与x,y点颜色相同的区域颜色为C 75 for(int j=1;j<=M;j++){ 76 if(a[i][j]==cc) 77 a[i][j]=fc; 78 } 79 break; 80 case 'S': 81 cin>>l; 82 cout<<l<<endl; //先输出文件名 83 for(int i=1;i<=N;i++){ //显示 84 for(int j=1;j<=M;j++) 85 cout<<a[i][j]; 86 cout<<endl; 87 } 88 break; 89 } 90 } 91 return 0; 92 } 93 94 /************************************************************** 95 Problem: 1498 96 User: freecode 97 Language: C++ 98 Result: Accepted 99 Time:0 ms 100 Memory:1328 kb 101 ****************************************************************/
Freecode : www.cnblogs.com/yym2013