viernes, 29 de noviembre de 2013

Uva: Cost Cutting 11727

package pkg11727costcutting;
import java.util.Scanner;


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

    byte casos,i=1;
    short medio,sal1,sal2,sal3;
    Scanner leo = new Scanner( System.in);

    casos=leo.nextByte();
    while(i<=casos){
        sal1 = leo.nextShort();
        sal2 = leo.nextShort();
        sal3 = leo.nextShort();
    
        System.out.print("Case "+i+": ");
        if (sal1>sal2)
            {if (sal2>sal3) System.out.println(sal2);
            //sal1>sal2 sal3>sal2
             else if (sal3>sal1) System.out.println(sal1);
                    else System.out.println(sal3);}
        else {if (sal1>sal3) System.out.println(sal1);
            //sal1>sal2 sal3>sal1
            else if (sal3>sal2) System.out.println(sal2);
            else System.out.println(sal3);}
        ++i;


    }

    }
}


Segunda solución (más rápida) /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pkg11727costcuttingb;

import java.util.Scanner;

/**
*
* @author Juan
*/


public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

    byte casos,i=1;
    short medio,sal1,sal2,sal3;
    Scanner leo = new Scanner( System.in);
 
    casos=leo.nextByte();
    while(i<=casos){
        sal1 = leo.nextShort();
        sal2 = leo.nextShort();
        sal3 = leo.nextShort();
        System.out.print("Case "+i+": ");
     
        if ((sal1>sal2 && sal2 >sal3) || (sal3>sal2 && sal2>sal1)) System.out.println(sal2);
        else if ((sal1>sal3 && sal3 >sal2) || (sal2>sal3 && sal3>sal1)) System.out.println(sal3);
        else System.out.println(sal1);
        ++i;
           }
    }
}