现在的位置: 首页 > 综合 > 正文

Uva 10267

2018年04月21日 ⁄ 综合 ⁄ 共 1568字 ⁄ 字号 评论关闭

图形化编辑器。

区域R的判断比较麻烦,其他很简单。

记住 行列别弄反了 - -

是大写字母O  不是数字0

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int map[300][300];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int n,m;
int x1,y1,x2,y2;
int Judge(int x,int y){
    if(x <= m && x >= 1 && y <= n && y >= 1) return 1;
    return 0;
}
void Creat(){
    scanf("%d%d",&m,&n);
    for(int i = 1;i <= m;i++)
        for(int j = 1;j <= n;j++)
            map[j][i] = 'O';
}
void Clear(){
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++)
            map[i][j] = 'O';
}
void Color(){
    int x,y;
    char str[3];
    scanf("%d%d%s",&x,&y,str);
    map[y][x] = str[0];
}
void DrawV(){
    char str[3];
    scanf("%d%d%d%s",&x1,&y1,&y2,str);
    if(y1 > y2){
        int y = y2;
        y2 = y1;
        y1 = y;
    }
    for(int i = y1;i <= y2;i++)
        map[i][x1] = str[0];
}
void DrawH(){
    char str[3];
    scanf("%d%d%d%s",&x1,&x2,&y1,str);
    if(x1 > x2){
        int x = x2;
        x2 = x1;
        x1 = x;
    }
    for(int i = x1;i <= x2;i++)
        map[y1][i] = str[0];
}
void DrawK(){
    char str[3];
    scanf("%d%d%d%d%s",&x1,&y1,&x2,&y2,str);
    if(y1 > y2){
        int y = y2;
        y2 = y1;
        y1 = y;
    }
    if(x1 > x2){
        int x = x2;
        x2 = x1;
        x1 = x;
    }
    for(int i = y1;i <= y2;i++)
        for(int j = x1;j <= x2;j++)
        map[i][j] = str[0];
}
void dfs(int x,int y,char c){
    char cc = map[y][x];
    if(cc == c) return ;
    map[y][x] = c;
    for(int i = 0;i < 4;i++){
        int xx = x + dx[i];
        int yy = y + dy[i];
        if(Judge(xx,yy) && map[yy][xx] == cc)
            dfs(xx,yy,c);
    }
}
void searchR(){
    int x,y;
    char str[3];
    scanf("%d%d%s",&x,&y,str);
    dfs(x,y,str[0]);
}
void Print(){
    char str[100];
    scanf("%s",str);
    puts(str);
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++)
            printf("%c",map[i][j]);
        printf("\n");
    }
}
int main(){
    char c;
    while(~scanf("%c",&c)){
        if(c == 'X')break;
        switch(c){
            case 'I':Creat();break;
            case 'C':Clear();break;
            case 'L':Color();break;
            case 'V':DrawV();break;
            case 'H':DrawH();break;
            case 'K':DrawK();break;
            case 'F':searchR();break;
            case 'S':Print();break;
        }
    }
    return 0;
}

【上篇】
【下篇】

抱歉!评论已关闭.