elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  problemas con la salida
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: problemas con la salida  (Leído 3,244 veces)
+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
problemas con la salida
« en: 14 Junio 2016, 22:54 pm »

este es el ejercicio
Código
  1.  
  2. Quirksome Squares
  3.  
  4. The number 3025 has a remarkable quirk: if you split its decimal representation in two strings of equal length (30 and 25) and square the sum of the numbers so obtained, you obtain the original number:
  5.  
  6. displaymath26
  7.  
  8. The problem is to determine all numbers with this property having a given even number of digits.
  9.  
  10. For example, 4-digit numbers run from 0000 to 9999. Note that leading zeroes should be taken into account. This means that 0001 which is equal to  tex2html_wrap_inline28 is a quirksome number of 4 digits. The number of digits may be 2,4,6 or 8. Although maxint is only 32767 and numbers of eight digits are asked for, a well-versed programmer can keep his numbers in the range of the integers. However efficiency should be given a thought.
  11.  
  12. Input
  13.  
  14. The input of your program is a textflle containing numbers of digits (taken from 2,4,6,8), each number on a line of its own.
  15.  
  16. Output
  17.  
  18. The output is a textfile consisting of lines containing the quirksome numbers (ordered according to the input numbers and for each input number in increasing order).
  19.  
  20. Warning: Please note that the number of digits in the output is equal to the number in the corresponding input line : leading zeroes may not be suppressed.
  21.  
  22. Sample Input
  23.  
  24. 2
  25. 2
  26. Sample Output
  27.  
  28. 00
  29. 01
  30. 81
  31. 00
  32. 01
  33. 81
  34.  

no entiendo como obtener esa salida, ayuda

no entiendo como obtener el output 00
01
81
00
01
81???
es el ejercicio 256 del juez uva de la universidad de valladolid


« Última modificación: 15 Junio 2016, 00:35 am por qwery.azc » En línea

+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: problemas con la salida
« Respuesta #1 en: 15 Junio 2016, 00:42 am »

ya lo entendi cuando lo programe lo posteo


En línea

+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: problemas con la salida
« Respuesta #2 en: 15 Junio 2016, 03:02 am »

funciona bien :)

Código
  1.  
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. public class Main {
  6.  
  7.    public static void main(String[] args) throws IOException {
  8.        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  9.        int max;
  10.        String cadenas;
  11.        int aux = 0;
  12.        int au2 = 0;
  13.  
  14.        while ((cadenas = bf.readLine()) != null) {
  15.            int cant = Integer.parseInt(cadenas);
  16.            ArrayList<Integer> coleccion = new ArrayList<>();
  17.            max = (int) Math.ceil(Math.pow(10, cant / 2));
  18.            for (int i = 0; i < Math.pow(max, 2); i++) {
  19.                aux = (int) (i / max);
  20.                au2 = (int) (i % max);
  21.                if (i == Math.pow(aux + au2, 2)) {
  22.                    coleccion.add(i);
  23.                }
  24.            }
  25.            for (int i = 0; i < coleccion.size(); i++) {
  26.  
  27.                System.out.printf("%0" + cant + "d%n", coleccion.get(i));
  28.            }
  29.            }
  30.        bf.close();
  31.        System.exit(0);
  32.    }
  33. }
  34.  
En línea

AlbertoBSD
Programador y
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.696


🏴 Libertad!!!!!


Ver Perfil WWW
Re: problemas con la salida
« Respuesta #3 en: 15 Junio 2016, 03:21 am »

Hola veo que te gustan los programas de concursos de programacion, he participado en varios y la verdad son un excelente ejercicio para el cerebro. Todo eso y a contra reloj  ;-) ;-)

No vi el mensaje antes a esa hora estaba trabajando.
Lo bueno que pudiste resolverlo.

Saludos
En línea

+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: problemas con la salida
« Respuesta #4 en: 15 Junio 2016, 15:20 pm »

gracias AlbertoBSD
ahora tengo otra duda

Código
  1. The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever performs best at some test. It is possible for any individual to inherit more than one or indeed all of the portions. To ensure that only highly intelligent people eventually become her successors, the Sultan has devised an ingenious test. In a large hall filled with the splash of fountains and the delicate scent of incense have been placed k chessboards. Each chessboard has numbers in the range 1 to 99 written on each square and is supplied with 8 jewelled chess queens. The task facing each potential successor is to place the 8 queens on the chess board in such a way that no queen threatens another one, and so that the numbers on the squares thus selected sum to a number at least as high as one already chosen by the Sultan. (For those unfamiliar with the rules of chess, this implies that each row and column of the board contains exactly one queen, and each diagonal contains no more than one.)
  2.  
  3. Write a program that will read in the number and details of the chessboards and determine the highest scores possible for each board under these conditions. (You know that the Sultan is both a good chess player and a good mathematician and you suspect that her score is the best attainable.)
  4.  
  5. Input
  6.  
  7. Input will consist of k (the number of boards), on a line by itself, followed by k sets of 64 numbers, each set consisting of eight lines of eight numbers. Each number will be a positive integer less than 100. There will never be more than 20 boards.
  8.  
  9. Output
  10.  
  11. Output will consist of k numbers consisting of your k scores, each score on a line by itself and right justified in a field 5 characters wide.
  12.  
  13. Sample input
  14.  
  15. 1
  16. 1  2  3  4  5  6  7  8
  17. 9 10 11 12 13 14 15 16
  18. 17 18 19 20 21 22 23 24
  19. 25 26 27 28 29 30 31 32
  20. 33 34 35 36 37 38 39 40
  21. 41 42 43 44 45 46 47 48
  22. 48 50 51 52 53 54 55 56
  23. 57 58 59 60 61 62 63 64
  24. Sample output
  25.  
  26.  260
  27.  
  28.  


como obtener 260???


En línea

AlbertoBSD
Programador y
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.696


🏴 Libertad!!!!!


Ver Perfil WWW
Re: problemas con la salida
« Respuesta #5 en: 15 Junio 2016, 15:42 pm »

Hola el numero es la suma de 8 de los 64 numeros en el tablero la tarea es colocar a las reinas en el tablero de tal forma que cumpla con la condicion de que ninguna reina se ataque y sea el numero mas alto posible.

La idea sería si s posible buscar una formación  o ul algorimo para colocar a las reinas y obtener la mayor suma.

Si gustas puedes abrir un topic por problema y los discutímos individualmente.

Sirve que les colocas un titulo mas descriptivo.

Saludos
« Última modificación: 15 Junio 2016, 15:44 pm por AlbertoBSD » En línea

+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: problemas con la salida
« Respuesta #6 en: 15 Junio 2016, 19:19 pm »

cuales son las reinas, lo hice diferente

mi idea fue sumar la diagonal de toda la matriz y creo que funciona pero nose
En línea

AlbertoBSD
Programador y
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.696


🏴 Libertad!!!!!


Ver Perfil WWW
Re: problemas con la salida
« Respuesta #7 en: 15 Junio 2016, 20:22 pm »

Ese es el problema tu tienes que colocar a las reinas son 8 y de hecho en la lectura dice las reglas son las mismas que en el ajedrez.

Otro detalle que los numeros no necesariamente van a estar en orden.

Saludos.
En línea

+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: problemas con la salida
« Respuesta #8 en: 16 Junio 2016, 00:59 am »

tengo otro problema interesante
Código
  1. The government of Nova Mareterrania requires that various legal documents have stamps attached to them so that the government can derive revenue from them. In terms of recent legislation, each class of document is limited in the number of stamps that may be attached to it. The government wishes to know how many different stamps, and of what values, they need to print to allow the widest choice of values to be made up under these conditions. Stamps are always valued in units of $1.
  2.  
  3. This has been analysed by government mathematicians who have derived a formula for n(h,k), where h is the number of stamps that may be attached to a document, k is the number of denominations of stamps available, and n is the largest attainable value in a continuous sequence starting from $1. For instance, if h=3, k=2 and the denominations are $1 and $4, we can make all the values from $1 to $6 (as well as $8, $9 and $12). However with the same values of h and k, but using $1 and $3 stamps we can make all the values from $1 to $7 (as well as $9). This is maximal, so n(3,2) = 7.
  4.  
  5. Unfortunately the formula relating n(h,k) to h, k and the values of the stamps has been lost--it was published in one of the government reports but no-one can remember which one, and of the three researchers who started to search for the formula, two died of boredom and the third took a job as a lighthouse keeper because it provided more social stimulation.
  6.  
  7. The task has now been passed on to you. You doubt the existence of a formula in the first place so you decide to write a program that, for given values of h and k, will determine an optimum set of stamps and the value of n(h,k).
  8.  
  9. Input
  10.  
  11. Input will consist of several lines, each containing a value for h and k. The file will be terminated by two zeroes (0 0). For technical reasons the sum of h and k is limited to 9. (The President lost his little finger in a shooting accident and cannot count past 9).
  12.  
  13. Output
  14.  
  15. Output will consist of a line for each value of h and k consisting of the k stamp values in ascending order right justified in fields 3 characters wide, followed by a space and an arrow (->) and the value of n(h,k) right justified in a field 3 characters wide.
  16.  
  17. Sample input
  18.  
  19. 3 2
  20. 0 0
  21. Sample output
  22.  
  23.  1  3 ->  7
  24.  

En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda problemas con salida VGA, PC no me da imagen
Hardware
MasterPM2 5 8,080 Último mensaje 22 Febrero 2013, 20:34 pm
por Aprendiz-Oscuro
Problemas de salida en Red Laboral
Redes
AngelMisha 2 2,160 Último mensaje 24 Junio 2014, 01:58 am
por AngelMisha
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines