|
171
|
Programación / Programación C/C++ / Re: Algoritmo movimiento caballo ajedrez
|
en: 24 Julio 2009, 13:19 pm
|
Vaya fallo más tonto lol xD No lo veía, gracias, os dejo el code terminado: /*Autor: El Aprendiz Fecha: 22-07-09 Version: 1.0 Resumen: Programa que calcula los posibles movimientos de un caballo en un tablero de ajedrez vacio y imprime las posiciones posibles en pantalla. */ #include <iostream> using namespace std; void caballo(int,int); int main() { int x,y; cout<<"Introduzca pos. x: "; cin>>x; cout<<endl<<"Introduzca pos. y: "; cin>>y; cout<<endl; caballo(x,y); cout<<endl; system("pause"); } void caballo(int x,int y) { int t=0; if ((x-2>=0 && x-2<=7) && (y-1>=0 && y-1<=7)) { cout<<++t<<" - ("<<x-2<<","<<y-1<<")"<<endl; } if ((x-2>=0 && x-2<=7) && (y+1>=0 && y+1<=7)) { cout<<++t<<" - ("<<x-2<<","<<y+1<<")"<<endl; } if ((x-1>=0 && x-1<=7) && (y+2>=0 && y+2<=7)) { cout<<++t<<" - ("<<x-1<<","<<y+2<<")"<<endl; } if ((x+1>=0 && x+1<=7) && (y+1>=0 && y+2<=7)) { cout<<++t<<" - ("<<x+1<<","<<y+2<<")"<<endl; } if ((x+2>=0 && x+2<=7) && (y+1>=0 && y+1<=7)) { cout<<++t<<" - ("<<x+2<<","<<y+1<<")"<<endl; } if ((x+2>=0 && x+2<=7) && (y-1>=0 && y-1<=7)) { cout<<++t<<" - ("<<x+2<<","<<y-1<<")"<<endl; } if ((x+1>=0 && x+1<=7) && (y-2>=0 && y-2<=7)) { cout<<++t<<" - ("<<x+1<<","<<y-2<<")"<<endl; } if ((x-1>=0 && x-1<=7) && (y-2>=0 && y-2<=7)) { cout<<++t<<" - ("<<x-1<<","<<y-2<<")"<<endl; } }
|
|
|
174
|
Programación / Programación C/C++ / Algoritmo movimiento caballo ajedrez
|
en: 22 Julio 2009, 22:19 pm
|
Bueno estoy haciendo un programa que me diga que combinaciones puede hacer un caballo en un tablero vacio segun unas coordenadas. Pero me falla por ejemplo al dar las coordenadas (6,2), os dejo el code a ver si me lo podéis arreglar y de paso si queréis optimizarlo un poquito porfavor. Gracias. PD: Seguro que es alguna tontería ya veréis pero no consigo verla. /* Autor: El Aprendiz Fecha: 22-07-09 Version: 1.0 Resumen: Programa que calcula los posibles movimientos de un caballo en un tablero de ajedrez vacio y imprime las posiciones posibles en pantalla. */ #include <iostream> using namespace std; void caballo(int,int); int main() { int x,y; cout<<"Introduzca pos. x: "; cin>>x; cout<<endl<<"Introduzca pos. y: "; cin>>y; cout<<endl; caballo(x,y); cout<<endl; system("pause"); } void caballo(int x,int y) { int t=0; if (x-2>=0 && y-1<=7) { cout<<++t<<" - ("<<x-2<<","<<y-1<<")"<<endl; } if (x-2>=0 && y+1<=7) { cout<<++t<<" - ("<<x-2<<","<<y+1<<")"<<endl; } if (x-1>=0 && y+2<=7) { cout<<++t<<" - ("<<x-1<<","<<y+2<<")"<<endl; } if (x+1>=0 && y+2<=7) { cout<<++t<<" - ("<<x+1<<","<<y+2<<")"<<endl; } if (x+2>=0 && y+1<=7) { cout<<++t<<" - ("<<x+2<<","<<y+1<<")"<<endl; } if (x+2>=0 && y-1<=7) { cout<<++t<<" - ("<<x+2<<","<<y-1<<")"<<endl; } if (x+1>=0 && y-2<=7) { cout<<++t<<" - ("<<x+1<<","<<y-2<<")"<<endl; } if (x-1>=0 && y-2<=7) { cout<<++t<<" - ("<<x-1<<","<<y-2<<")"<<endl; } }
|
|
|
177
|
Programación / Programación Visual Basic / Re: AyuDa, Cierta Cantidad De Letras en Un TextBox
|
en: 11 Julio 2009, 01:36 am
|
Se refiere a que tu tienes un textbox asi:
Hay 100 caracteres:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111xxxxxxxxxx
El se refiere que cuando pulsas otros caracteres, por ejemplo: 4e7jfg
4e7jfg111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111xxxx
Se borren los del final que no caben y se metan esos en el principio.
No se si he hecho bien los esquemas pero espero que capteis la idea.
|
|
|
178
|
Programación / Ejercicios / Re: Urgente necesito realizar programa para entregar esta noche
|
en: 9 Julio 2009, 16:58 pm
|
#include <iostream.h> #include <stdlib.h>
int operacion(int [][100], int [][100], int [][100], int , int , int, int, int); . int main() { int n,f,c,r,f1,f2,c1,c2, m1[100][100], m2[100][100], mr[100][100]; . cout<<"1 -- Sumar"<<endl<<"2 -- Restar"<<endl<<"Otro numero -- Salir"<<endl; cin>>n; while ((n>0) && (n<3)) { . f1=0; c1=0; f2=0; c2=0; while ((f1<1) || (f1>101)) { cout<<"Introduce las filas de la matriz 1 [1-100]: "; cin>>f1; } while ((c1<1) || (c1>101)) { cout<<"Introduce las columnas de la matriz 1 [1-100]: "; cin>>c1; } for (f=0; f<=f1; f++) { . for (c=0; c<=c1; c++) { cout<<"m1["<<f<<"]["<<c<<"] = "; cin>>m1[f][c]; } . } while ((f2<1) || (f2>101)) { cout<<endl<<"Introduce las filas de la matriz 2 [1-100]: "; cin>>f2; } while ((c2<1) || (c2>101)) { cout<<"Introduce las columnas de la matriz 2 [1-100]: "; cin>>c2; } for (f=0; f<=f2; f++) . { . for (c=0; c<=c2; c++) { cout<<"m2["<<f<<"]["<<c<<"] = "; cin>>m2[f][c]; } . } r=operacion(m1,m2,mr,n,f1,f2,c1,c2); . if (r==-1) cout<<endl<<"No se pudo realizar la operacion ya que el tamaño de las matrices no coincide"; . else { for (f=0; f<=f2; f++) . { . for (c=0; c<=c2; c++) . cout<<" "<<mr[f][c]<<" "; . cout<<endl; . } . } . cout<<endl<<"1 -- Sumar"<<endl<<"2 -- Restar"<<endl<<"Otro numero -- Salir"<<endl; cin>>n; } cout<<endl<<"Fin de programa..."<<endl; . system("PAUSE"); . return 0; } . int operacion(int m1[][100], int m2[][100], int mr[][100], int n, int f1, int f2,int c1, int c2) { . int f,c; . if ((f1==f2) && (c1==c2)) //si si se pueden sumar/restar . { . if (n==1) //suma . { for (f=0; f<=f1; f++) . { . for (c=0; c<=c1; c++) . mr[f][c] = m1[f][c] + m2[f][c]; . } } else //resta . { for (f=0; f<=f1; f++) { for (c=0; c<=c1; c++) . mr[f][c] = m1[f][c] - m2[f][c]; . } . } return 1; . } . else . {return -1;} . }
Y pregunto yo, donde estan las clases?
|
|
|
179
|
Programación / Ejercicios / Re: [EJERCICIO] El juego de "Que ves?"
|
en: 16 Mayo 2009, 23:25 pm
|
no será tu tarea de programación?
Que parte de esto no entiendes? Los tres ejercicios son míos, ni copiados de un libro, ni de internet, ni de una revista, etc... Han sido redactados y creados por mi, si alguien desea incluirlos en una web o similar solicitadme permiso.
|
|
|
|
|
|
|