Está en la página 1de 4

public class sopadeletras { public static void main(String []args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.

in)) ; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)) ; String sopa = new String(); int n=3; char A[][] = new char[n][n]; for(int i=0; i<=n-1; i++){ for (int j=0; j<=n-1; j++){ A[i][j]=(char) System.in.read(); } } for(int i=0; i<=n-1; i++){ //muestro la matriz para verificar los valore s for (int j=0; j<=n-1; j++){ System.out.println(A[i][j]); } } } }

for (int i=0; i<paraules.length;i++){ j=0; trobada=false; acumular=0; while (j<paraules[i].length()){ letra = palabras[i].charAt(j); salir=false; k=inici; while (salir==false && k<caracters.length){ if(letra==caracters[k]){ salir=true; acumula++; inicio=k+1; } }

if(si==true){ System.out.println("La palabra"+[i]+"seencuentra"+posi+","+posf); }else{ System.out.println("La palabra"+[i]+"noseencuentra"); } }

import java.awt.*;import java.awt.event.*;//*********************************** import javax.swing.JApplet;import javax.swing.JFrame;import javax.swing.JButton; import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuItem; import javax.swing.JMenuBar;import javax.swing.ImageIcon;import javax.swing.JTab le;import javax.swing.JFormattedTextField;import javax.swing.table.AbstractTable Model;import javax.swing.table.DefaultTableModel; public class SopaLetras exten ds JApplet { public SopaLetras(){ //frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); JDK 1.3+ /* ventana.addWindo wListener(new java.awt.event.WindowAdapter(){ public void windowClosin g(WindowEvent e){ System.exit(0); } } ); */ //Lista_de_Menus ventana = new Lista_de_Menus(); //JFrame ventana = new JFrame("Creador de Sopa de Letras"); //ventan a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label1 = new JL abel("Elige el MODO para llenar la matriz"); JButton b1 = new JButton ("I mprimir"); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMe nu(); JMenuItem menuItem = new JMenuItem(); DefaultTableMode l datos = new DefaultTableModel(20,38); JTable tabla = new JTable(datos) ; JFormattedTextField campoTexto = new JFormattedTextField(); //campoTexto.setHorizontalAlignment(); //datos.addColumn("ID"); //datos.addRow(Array) datos.setValueAt(" "+'C',0,0); datos.setValu eAt(" "+'A',1,0); datos.setValueAt(" "+'S',2,0); datos.setValueAt( " "+'A',3,0); menu = new JMenu("Modo de Creacion"); menuBar.add(m enu); menuItem = new JMenuItem("Manual" //,new ImageIcon("")); ); menu.add(menuItem); menuItem = new JMenuItem("Auto" //,new ImageIcon("")); ); menu.add(menuItem); Gr idBagLayout grigbag = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(3,3,3,3); //ven tana.getContentPane().setLayout(grigbag); setLayout(grigbag); gbc .gridx = 0; gbc.gridy = 0; gbc.gridwidth = GridBagConstraints.REMA INDER; gbc.gridheight = 2; gbc.fill =GridBagConstraints.BOTH; gbc.weightx=1.0; gbc.weighty=1.0; //ventana.getContentPane(). add (menuBar, gbc); add (menuBar, gbc); gbc.gridx = 20; gb c.gridy = 4; gbc.gridwidth = 5; gbc.gridheight = 1; //vent ana.getContentPane().add (label1, gbc); add (label1, gbc); gbc.gr idx = 20; gbc.gridy = 5; gbc.gridwidth = GridBagConstraints.REMAIN DER; gbc.gridheight = 1; gbc.fill = GridBagConstraints.BOTH; //ventana.getContentPane().add (tabla, gbc); add (tabla, gbc); gbc.gridx = 20; gbc.gridy = 6; gbc.gridwidth = 3; gbc.gri dheight = 1; gbc.anchor = GridBagConstraints.CENTER; gbc.weightx= 1.0; //ventana.getContentPane().add (b1, gbc); add (b1, gbc); //* *************************************** //ventana.pack(); //venta na. setSize(800,500); //ventana.setResizable(false); //vent ana.setVisible(true);} public void init(){ SopaLetras sL = new SopaLetras() ;} }

import java.util.Random; import java.util.Date; import java.lang.Math; class P alabras { public String palabra; public Palabras sgte; Palabras(String p){ palab ra = p; sgte = null; } } class Lista { private Palabras primero; Lista(){ prim ero = null; } /* * consideraciones a la hora de agregar: * - la longitud de la p alabra mas larga* - ordenar de forma que la palabra mas larga quede primero y la ult seria las mas corta* - ...*/ public void insertarPalabra (String p){ Pala bras aux = new Palabras (p); if(primero == null) primero = aux; else{ aux.sgte = primero; primero = aux; } } public void mostrarLista(){ Palabras aux = primero; int i=1; System.out.println("- Mostrar -"); while(aux != null){ System.out.prin tln("Palabra N "+i+": "+aux.palabra); aux=aux.sgte; i++; } } } public class CreaS opa { public static void main(String[] args) throws java.io.IOException { List a lP = new Lista(); Random r = new Random(); String[] pSL = {"SOL","MESA","CASA" }; String lA = new String ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); int r1, r2; //r.setSee d(123456789); r.setSeed(new Date().getTime()); r1 = r.nextInt(lA.length()); r2 = (int)(Math.random() * lA.length()); System.out.println(lA.charAt(r1)); System.o ut.println(lA.charAt(r2)); lP.insertarPalabra(lA[0]); lP.mostrarLista(); } }

import java.util.Random;import java.util.Date;import java.util.List;import java. util.Iterator;import java.util.ArrayList;import java.util.ListIterator;import ja va.util.HashSet;import java.util.Set;import java.util.Collections;import java.ut il.Vector;import java.lang.Math; class Palabras { public String palabra; public Palabras sgte; Palabras(String p){ palabra = p; sgte = null; }} class Lista { private Palabras primero; Lista(){ primero = null; } public Palabras mostrarNodoAnterior(Palabras p){ if(primero == p) return null; else{ Palabras aux = primero; while(aux.sgte != p) aux = aux.sgte; return aux; } } public v oid insertarPalabra(String p){ Palabras num = new Palabras (p); Palabras i = primero; if(primero == null) primero = num; else{ while((p.length() <= i.palabra.l ength()) && (i.sgte != null)) i = i.sgte; if(p.length() > primero.palabra.length()){ num.sgte = prime ro; primero = num; }else if (p.length() > i.palabra.length()){ num.sgte = i; mostrarNodoAnterior(i).sgte = num; }else{ i.sgte = num; } } } public void most rarLista(){ Palabras aux = primero; int i=1; System.out.println("- Mostrar -"); while(aux != null){ System.out.println("Palabra N "+i+": "+aux.palabra); aux=aux. sgte; i++; } } public Vector busqP (Str ing term){ //busqP(""); Vector pE = new Vector(); Palabras dic = primero; int contAC = 0, contLV = 0; for(;dic != null; dic = dic.sgte){ if(dic.palabra.length() <= term. length()){ for(int letra = 0; letra < term.length() ; letra++){ if(term.charAt(letra) != '-'){ contLV++; if(term.charAt(letra) == dic.palabra.charAt(letra)) contAC++; } } if(contLV == contAC) pE.addElement(dic.palabra); contLV = 0; contAC = 0; } } return pE; //pE.addElement("CASA"); //pE.size(); //pE.elementAt(i ); }}public class CreaSopa { public static void main(String[] args) thr

ows java.io.IOException { Lista lP = new Lista(); Random r = new R andom(); String[] pSL = {"SOL","MESAS","CASA","JAPONES","CARRO"," CAZADOR","P-DS"}; String lA = new String ("ABCDEFGHIJKLMNOPQRSTUVW XYZ"); char[][] tablero = new char[10][10]; int r1, r2; //r.setSeed(123456789); r.setSeed(new Date().getTime()); r1 = r.nextInt(lA.length()); r2 = (int)(Math.random() * lA.length()); System.out.println(lA.charAt(r1)); System.out.println(lA.charAt(r2) ); lP.insertarPalabra(pSL[0]); lP.insertarPalabra(pSL[1 ]); lP.insertarPalabra(pSL[2]); lP.insertarPalabra(pSL[3 ]); lP.insertarPalabra(pSL[4]); lP.insertarPalabra(pSL[5 ]); lP.insertarPalabra(pSL[6]); lP.mostrarLista(); if((lP.busqP("-E---").size()) > 0){ for(int i = 0; i < (lP.b usqP("-E---").size()); i++) System.out.println("-E--: "+lP.busqP("-E---").elementAt(i)); } for(int i = 0; i < tablero.length; i++) for(int j = 0; j < tablero[i].length; j+ +) tablero[i][j] = '-'; for(int contPA = 0; contPA < 1;){ int randF, randC, randSigF, randSigC, te mpF = 0, tempC = 0; randF = (int)(Math.random() * 10); randC = (int)(Math.random() * 10); randSigF = (int)(Math.ra ndom() * 2); randSigC = (int)(Math.random() * 2); if(tablero[randF][randC] == '-'){ tablero[randF][r andC] = 'A'; contPA++; } } for(int i = 0; i < tablero.length; i++){ for(int j = 0; j < tablero[i].length; j++){ System.o ut.print(tablero[i][j]); } System.out.print("n"); } /* List<String> lis ta = new ArrayList<String>(); lista.add("PRUEBA"); lista.ad d("MMMMM..."); Iterator iter = lista.iterator(); for(int i = 1;iter.hasNext(); i++) System.out.println(i+" "+iter.ne xt()+ " "+lista.size()); ListIterator listIt = lista.listIterator (lista.size()); while(listIt.hasPrevious()) System.out.println(listIt.previous()); */ }}