Ola a todos este es el examen de la I Unidad del Laboratorio de Estructura de Datos, el profesor pidio implementar el Buscaminas ; en las demas unidades no tomo examen..., espero les sirva... Saludos.
// BUSCAMINAS
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
char M[100][100];
int cont;
int f,c,i,j,k,p;
system("title BUSCAMINAS");
system("color 9F");
char R='S';
do
{
/* ingresa tamaño de matriz y valida */
do
{
cout<<endl<<"\t\t+--------------------------------------------------+ ";
cout<<endl<<"\t\t| 1ER EXAMEN DE ESTRUCTURA DE DATOS | ";
cout<<endl<<"\t\t| BUSCAMINAS(RELEASE) | ";
cout<<endl<<"\t\t| - [ UNIVERSIDAD NACIONAL DE TRUJILLO ] - | ";
cout<<endl<<"\t\t| Copyright © Company InfoBik's (JP. Rodriguez) | ";
cout<<endl<<"\t\t+--------------------------------------------------+ ";
cout<<endl<<endl;
cout<<" Ingrese el numero de filas: ";
cin>>f;
cout<<" Ingrese el numero de columnas: ";
cin>>c;
cout<<endl;
if((f<1)||(c<1))
{ system("cls"); }
}
while((f<1)||(c<1));
/* ingresamos caracteres en las posiciones de la matriz*/
cout<<endl;
for(i=0;i<f;i++)
{
for(j=0;j<c;j++)
{
do /* validamos q sea - y * los caracteres ingresados*/
{
cout<<" Ingrese el caracter (-) o (*) en la fila "<<"["<<i+1<<"], columna["<<j+1<<"]: ";
cin>>M[i][j];
}
while((M[i][j]!='-')&&(M[i][j]!='*'));
}
}
/*mostramos la matriz ingresada*/
cout<<endl;
cout<<" LA MATRIZ INGRESADA ES: ";
cout<<endl<<endl;
for(i=0;i<f;i++)
{
for(j=0;j<c;j++)
{ cout<<" "<<M[i][j]; }
cout<<endl;
}
/* busca en las esquinas */
if(M[0][0]=='-')
{
cont=0;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[0][0]=M[0][0]+3+cont;
}
if(M[0][c-1]=='-')
{
cont=0;
for(i=0;i<2;i++)
{
for(j=c-2;j<c;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[0][c-1]=M[0][c-1]+3+cont;
}
if(M[f-1][0]=='-')
{
cont=0;
for(i=f-2;i<f;i++)
{
for(j=0;j<2;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[f-1][0]=M[f-1][0]+3+cont;
}
if(M[f-1][c-1]=='-')
{
cont=0;
for(i=f-2;i<f;i++)
{
for(j=c-2;j<c;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[f-1][c-1]=M[f-1][c-1]+3+cont;
}
/* buscamos en las aristas */
for(k=1;k<c-1;k++)
{
if(M[0][k]=='-')
{
cont=0;
for(i=0;i<2;i++)
{
for(j=k-1;j<k+2;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[0][k]=M[0][k]+3+cont;
}
}
for(k=1;k<c-1;k++)
{
if(M[f-1][k]=='-')
{
cont=0;
for(i=f-2;i<f;i++)
{
for(j=k-1;j<k+2;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[f-1][k]=M[f-1][k]+3+cont;
}
}
for(k=1;k<f-1;k++)
{
if(M[k][0]=='-')
{
cont=0;
for(i=k-1;i<k+2;i++)
{
for(j=0;j<2;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[k][0]=M[k][0]+3+cont;
}
}
for(k=1;k<f-1;k++)
{
if(M[k][c-1]=='-')
{
cont=0;
for(i=k-1;i<k+2;i++)
{
for(j=c-2;j<c;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[k][c-1]=M[k][c-1]+3+cont;
}
}
/* buscamos en el centro */
for(k=1;k<f-1;k++)
{
for(p=1;p<c-1;p++)
{
if(M[k][p]=='-')
{
cont=0;
for(i=k-1;i<k+2;i++)
{
for(j=p-1;j<p+2;j++)
{
if(M[i][j]=='*')
{ cont++; }
}
}
M[k][p]=M[k][p]+3+cont;
}
}
}
/* mostramos el resultado */
cout<<endl;
cout<<" LA MATRIZ RESULTANTE ES: ";
cout<<endl<<endl;
for(i=0;i<f;i++)
{
for(j=0;j<c;j++)
{ cout<<" "<<M[i][j]; }
cout<<endl<<endl;
}
cout<<" DESEA CONTINUAR [S/N] : ";
cin>>R;
cout<<endl;
system("CLS");
}
while ( R == 'S' || R == 's' );
}
No hay comentarios.:
Publicar un comentario