Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EJERCICIO 1 (MATRIZ IDENTIDAD)
- #include <stdio.h>
- int re_diagonal ( int filas,int matriz[][filas]);
- int re_ceros ( int filas,int matriz[][filas]);
- int main (void){
- int flag_ceros,flag;
- int filas;
- int i,j;
- do{
- scanf("%d",&filas);
- int matriz[filas][filas];
- if(filas <= 0){
- break;
- }
- for(i=0;i<filas;i++){
- for(j=0;j<filas;j++){
- scanf("%d",&matriz[i][j]);
- }
- }
- flag=re_diagonal(filas,matriz);
- flag_ceros=re_ceros(filas,matriz);
- if ((flag_ceros == 1) && (flag == 1)) {
- printf("SI\n");
- }
- else{
- printf("NO\n");
- }
- }while(filas > 0);
- }
- int re_diagonal (int filas,int matriz[][filas]){
- int i;
- int cont=0;
- for(i=0;i<filas;i++){
- if(matriz[i][i] == 1){
- cont++;
- }
- }
- if (cont == filas){
- return 1;
- }
- else{
- return 0;
- }
- }
- int re_ceros (int filas,int matriz[][filas]){
- int i,j;
- int cont=0;
- for(i=0;i<filas;i++){
- for(j=0;j<filas;j++){
- if(matriz[i][j]==0){
- cont++;
- }
- }
- }
- if( cont == ((filas*filas)-filas) ){
- return 1;
- }
- else{
- return 0;
- }
- }
- EJERCICIO 2 (BUSCAMINAS)
- #include <stdio.h>
- int cuentaMinas (int filas,int columnas,char matriz[][columnas]);
- int main (void){
- int filas,columnas;
- int total=0;
- do{
- scanf("%d %d",&columnas,&filas);
- getchar();
- if((filas > 0) && (columnas > 0)){
- char matriz[filas][columnas];
- int i,j;
- for(i=0;i<filas;i++){
- for(j=0;j<columnas;j++){
- scanf("%c",&matriz[i][j]);
- }
- getchar();
- }
- total=cuentaMinas(filas,columnas,matriz);
- printf("%d\n",total);
- }
- }while((filas != 0) && (columnas != 0));
- }
- int cuentaMinas (int filas,int columnas,char matriz[][columnas]){
- int i,j,minas,cont;
- cont=0;
- for(i=1;i<filas-1;i++){
- for(j=1;j<columnas-1;j++){
- minas=0;
- if(matriz[i][j] == '-'){
- if(matriz[i-1][j-1]=='*'){
- minas++;
- }
- if(matriz[i-1][j]=='*'){
- minas++;
- }
- if(matriz[i-1][j+1]=='*'){
- minas++;
- }
- if(matriz[i][j-1]=='*'){
- minas++;
- }
- if(matriz[i][j+1]=='*'){
- minas++;
- }
- if(matriz[i+1][j-1]=='*'){
- minas++;
- }
- if(matriz[i+1][j]=='*'){
- minas++;
- }
- if(matriz[i+1][j+1]=='*'){
- minas++;
- }
- }
- if(minas >= 6){
- cont++;
- }
- }
- }
- return cont;
- }
- EJERCICIO 3 (SOMBRAS EN EL CAMPING)
- #include <stdio.h>
- //------------------------PROTOTIPO DE FUNCIONES--------------------------------------------------
- void iniciacion (int filas,int columnas,int matriz[][columnas]);
- void asignacion_arboles ( int filas, int columnas , int matriz[][columnas],int largo);
- void sombras (int filas, int columnas, int matriz[][columnas]);
- void cuenta_sombras (int filas, int columnas,int matriz[][columnas]);
- //--------------PROGRAMA PRINCIPAL-------------------
- int main (void){
- int filas,columnas,arboles;
- do{
- scanf("%d%d%d",&columnas,&filas,&arboles);
- if((filas==0)&&(columnas==0)&&(arboles == 0)) break;
- int matriz[filas+1][columnas+1];
- if( (arboles == 0) && (filas!=0) && (columnas!=0)){
- printf("0\n");
- }
- else{
- iniciacion(filas,columnas,matriz);
- asignacion_arboles(filas,columnas,matriz,arboles);
- sombras(filas,columnas,matriz);
- cuenta_sombras(filas,columnas,matriz);
- }
- }while ( (filas != 0) && (columnas != 0) );
- return 0;
- }
- //-------------------------FUNCIONES A UTILIZAR------------------------------------------------
- void iniciacion (int filas,int columnas,int matriz[][columnas]){//LIMPIA MATRIZ
- int i,j;
- for(i=1;i<=filas;i++){
- for(j=1;j<=columnas;j++){
- matriz[i][j]=0;
- }
- }
- }
- void asignacion_arboles (int filas, int columnas , int matriz[][columnas],int largo){// ASIGNA UBICACION DE LOS ARBOLES.
- int i,x,y;
- for(i=0;i<largo;i++){
- scanf("%d %d",&x,&y);
- matriz[y][x]=1;
- }
- }
- void sombras (int filas, int columnas, int matriz[][columnas]){ //ASIGNA UBICACION DONDE HABRA SOMBRA POR CADA ARBOL.
- int i,j;
- for(i=1;i<=filas;i++){
- for(j=1;j<=columnas;j++){
- if(matriz[i][j] == 1){
- if((matriz[i-1][j-1] != 1) && (i-1 >= 1) && (j-1 >= 1)){
- matriz[i-1][j-1]=3;
- }
- if((matriz[i-1][j]!=1)&&(i-1 >= 1)){
- matriz[i-1][j]=3;
- }
- if((matriz[i-1][j+1]!=1)&&(i-1>=1)&&(j+1 <= columnas)){
- matriz[i-1][j+1]=3;
- }
- if((matriz[i][j-1]!=1)&&(j-1 >=1)){
- matriz[i][j-1]=3;
- }
- if((matriz[i][j+1]!=1)&&(j+1<=columnas)){
- matriz[i][j+1]=3;
- }
- if((matriz[i+1][j-1]!=1)&&(i+1 <=filas)&&(j-1>=1)){
- matriz[i+1][j-1]=3;
- }
- if((matriz[i+1][j]!=1)&&(i+1 <= filas)){
- matriz[i+1][j]=3;
- }
- if((matriz[i+1][j+1]!=1) && (i+1 <= filas)&&(j+1<=columnas)){
- matriz[i+1][j+1]=3;
- }
- }
- }
- }
- }
- void cuenta_sombras (int filas, int columnas,int matriz[][columnas]){ //REALIZA LA CUENTA DE LA CANTIDAD DE CARPAS QUE PUEDEN QUEDAR CUBIERTAS POR SOMBRA
- int i,j;
- int cont=0;
- for(i=1;i<=filas;i++){
- for(j=1;j<=columnas;j++){
- if(matriz[i][j]==3){
- cont++;
- }
- }
- }
- printf("%d\n",cont);
- }
Add Comment
Please, Sign In to add comment