CIJEVI - Cijevi

Tác giả: hieult

Ngôn ngữ: C++

#include <cstdio>
#include <cstring>
//#include <conio.h>


char a[30][30];
int n,m;

bool trai(int r,int c){ return ((c>=0) && (a[r][c-1]=='+' || a[r][c-1]=='-' || a[r][c-1]=='1' || a[r][c-1]=='2')); }
bool phai(int r,int c){ return ((c<m)&& (a[r][c+1]=='+' || a[r][c+1]=='-' || a[r][c+1]=='3' || a[r][c+1]=='4')); }
bool tren(int r,int c){ return ((r>=0) && (a[r-1][c]=='+' || a[r-1][c]=='|' || a[r-1][c]=='1' || a[r-1][c]=='4')); }
bool duoi(int r,int c){ return ((r<n) && (a[r+1][c]=='+' || a[r+1][c]=='|' || a[r+1][c]=='2' || a[r+1][c]=='3')); }

int main()
{
 //   freopen("CIJEVI.in","r",stdin);
    scanf("%d %d",&n,&m);
    for(int i = 0;i<n;i++)
        scanf("%s",a[i]);
    for(int i = 0;i<n;i++)
        for(int j = 0;j<m;j++)
        {
                if(a[i][j] == '.')
                {
                if(trai(i,j)&&phai(i,j)&&tren(i,j)&&duoi(i,j)) {printf("%d %d +",i+1,j+1); return 0;}
                if(trai(i,j)&&phai(i,j)) {printf("%d %d -",i+1,j+1); return 0;}
                if(tren(i,j)&&duoi(i,j)) {printf("%d %d |",i+1,j+1); return 0;}
                if(trai(i,j)&&duoi(i,j)) {printf("%d %d 4",i+1,j+1); return 0;}
                if(trai(i,j)&&tren(i,j)) {printf("%d %d 3",i+1,j+1); return 0;}
                if(phai(i,j)&&duoi(i,j)) {printf("%d %d 1",i+1,j+1); return 0;}
                if(phai(i,j)&&tren(i,j)) {printf("%d %d 2",i+1,j+1); return 0;}
                }
        }
   // getch();
}

Download