miércoles, 21 de enero de 2015

Solución UVA Tex Quotes

package TEX_Quotes_272;

import java.util.Scanner;

public class TEX_Quotes_272 {

    public static void main(String[] args) {
        String cadena;
        Scanner leer = new Scanner(System.in);
        int cont = 1;

        do {

            cadena = leer.nextLine();

            for (int i = 0; i < cadena.length(); i++) {
                if (cadena.charAt(i) == '"') {
                    if (cont % 2 != 0) {
                        System.out.print("``");
                    } else {
                        System.out.print("''");
                    }
                    cont++;
                } else {

                    System.out.print(cadena.charAt(i));
                }
            }
            System.out.println();
        } while (leer.hasNext());
    }
}

Solución UVA 1585 Score


package Puntuacion_1585;

import java.util.Scanner;

public class Puntuacion_1585 {

    public static void main(String[] args) {
        int num;
        String respuesta;
        boolean spree = true;
        int conteo;
        int puntaje;

        Scanner leer = new Scanner(System.in);

        num = leer.nextInt();
        leer.nextLine();
        for (int i = 0; i < num; i++) {

            respuesta = leer.nextLine();

            puntaje = 0;
            conteo = 0;

            for (int j = 0; j < respuesta.length(); j++) {
                if (!spree) {
                    conteo = 0;

                }
                if (respuesta.charAt(j) == 'O') {
                    conteo = conteo + 1;
                    puntaje = puntaje + conteo;
                    spree = true;
                } else {
                    spree = false;
                }
            }
         
            System.out.println(puntaje);
        }
    }
}

Solucion 1585


Solución UVA 1585

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg1585uva;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);
        int suma = 0, sumatotal = 0, casos, cont = 0;
        String cadena;
        System.out.println("Introduce los numeros de casos");
        casos = entrada.nextInt();
        do {

            cadena = entrada.next();
            cont++;
            for (int i = 0; i < cadena.length(); i++) {
                if (cadena.charAt(i) == 'O') {
                    suma++;
                    sumatotal = sumatotal + suma;
                } else if (cadena.charAt(i) == 'X') {
                    suma = 0;

                }
            }
            System.out.println(sumatotal);
            sumatotal = 0;

        } while (casos != cont);

    }

}

Solucionado por Jesús
Enlace de referencia: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4460

Solución UVA 1585 Score

import java.util.Scanner;
/**
 *
 * @author juan
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner leer = new Scanner(System.in);
        int total;
        int parcial;
        int casos;
        String caso;
       
        casos= leer.nextInt();
        leer.nextLine();
        for (int i = 0; i < casos; i++) {
            caso=leer.nextLine();
            total=parcial=0;
            for (int j = 0; j < caso.length(); j++) {
                if (caso.charAt(j)=='O')
                {
                    parcial++;
                    total+=parcial;
                }
                else parcial=0;
               
            }
            System.out.println(total);
        }
       
       
       
   
    }
   
}

Solucion uva 737

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package uva737;
import java.util.Scanner;

/**
 *
 * @author Juan
 */
public class Uva737 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner leer = new Scanner(System.in);
        int vol,cubos,lado,x,y,z,inx,iny,
inz,finx,finy,finz;
       
           
         cubos=leer.nextInt();
         while (cubos>0){
             inx=leer.nextInt();
             iny=leer.nextInt();
             inz=leer.nextInt();
             lado=leer.nextInt();
             finx=inx+lado;
             finy=iny+lado;
             finz=inz+lado;
             for (int i = 1; i < cubos; i++) {
                 x=leer.nextInt();
                 y=leer.nextInt();
                 z=leer.nextInt();
                 lado=leer.nextInt();
                 inx=Math.max(inx, x);
                 iny=Math.max(iny, y);
                 inz=Math.max(inz, z);
                 finx=Math.min(finx, x+lado);
                 finy=Math.min(finy, y+lado);
                 finz=Math.min(finz, z+lado);
                
             }
             vol=Math.max(0, (finx-inx)*(finy-iny)*(finz-inz));
             System.out.println(vol);
            
             cubos = leer.nextInt();
         }
    }
}
http://solucionesuva.blogspot.com.es/2015/01/737-gleaming-cubes.html

Solucion 1585 Puntuacion

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package UVA;

import java.util.Scanner;

/**
 *
 * @author dam116
 */
public class UVA1585_Puntuacion {

    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);
        String cadena;
        int valor = 1, num, nota = 0;
        num = entrada.nextInt();
        for (int i = 0; i < num; i++) {
            cadena = entrada.next();
            for (int j = 0; j < cadena.length(); j++) {
                if (cadena.charAt(j) == 'O') {
                    nota += valor;
                    valor++;
                }else{
                    valor = 1;
                }
            }
            System.out.println(nota);
            nota = 0;
            valor = 1;
        }
    }
}
Solucionado por Santiago y Amanda