Pagini recente » Cod sursa (job #1042863) | Cod sursa (job #470940) | tema | Cod sursa (job #2529462) | Cod sursa (job #1842256)
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int n,m,a[102][102],b[102][102],c[9],x,y,nr2;
char s[101];
ifstream f("ceva.txt");
ofstream g("nume2.txt");
void citire()
{
f>>n>>m;
f.getline(s,100);
for(int i=1;i<=n;i++)
{
f.getline(s,100);
for(int j=1;j<=m;j++)
if(j<=strlen(s))
{
if(s[j-1]=='R')
{
a[i][j]=-2;
b[i][j]=-2;
}
else
if(s[j-1]=='J')
{
a[i][j]=-3;
b[i][j]=-3;
}
else
if(s[j-1]=='X')
{
a[i][j]=-1;
b[i][j]=-1;
}
else
{
a[i][j]=0;
b[i][j]=0;
}
}
else
{
a[i][j]=0;
b[i][j]=0;
}
}
}
int verif()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]==b[i][j] && a[i][j]>0)
{
nr2=a[i][j];
x=i;
y=j;
return 1;
}
return 0;
}
int mini2(int i,int j)
{
for(int h=i-1;h<=i+1;h++)
for(int g=j-1;g<=j+1;g++)
if(b[h][g]==-3 && (h!=i || g!=j))
return 2;
int l=0;
for(int h=i-1;h<=i+1;h++)
for(int g=j-1;g<=j+1;g++)
if(b[h][g]>0 && (h!=i || g!=j))
{
l++;
c[l]=b[h][g];
}
if(l==0)
return 0;
int nr=c[1];
for(int g=2;g<=l;g++)
if(c[g]<nr)
nr=c[g];
return nr+1;
}
int mini(int i,int j)
{
for(int h=i-1;h<=i+1;h++)
for(int g=j-1;g<=j+1;g++)
if(a[h][g]==-2 && (h!=i || g!=j))
return 2;
int l=0;
for(int h=i-1;h<=i+1;h++)
for(int g=j-1;g<=j+1;g++)
if(a[h][g]>0 && (h!=i || g!=j))
{
l++;
c[l]=a[h][g];
}
if(l==0)
return 0;
int nr=c[1];
for(int g=2;g<=l;g++)
if(c[g]<nr)
nr=c[g];
return nr+1;
}
void caut()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(a[i][j]==0)
a[i][j]=mini(i,j);
if(b[i][j]==0)
b[i][j]=mini2(i,j);
}
}
int main()
{
citire();
while(verif()==0)
caut();
g<<nr2<<" "<<x<<" "<<y;
}