1.

package sem2.am.lovecalculator;

/**
* Angewandte Mathematik, SS11
* Problem: 10424 Love Calculator
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1365
*
* @author Sommer Franz
* @author Stein Florian
* @version 0.X, 03/27/2011
*
* Method : Ad-Hoc
* Status : Wrong Answer
* Runtime: xxx
*/

import java.text.DecimalFormat;
import java.util.*;

class Main {

public static void main(String[] args) throws Exception {
// ******************************************
// 1. Retrieve Input
// ******************************************

Scanner scanner = new Scanner(System.in);
scanner.useDelimiter("\\n");

// ******************************************
// 2. Now the length of the Input
// ******************************************
int inputlength = 2;

// ******************************************
// 3. The idea is to read all lines at once to a String array and from
// there to a char array
// Strings are stored in lovers[i][j][0]
// The Sum of all Char Values is stored in loversInt[i][j][1]
// ******************************************

// ********************************************************************************************************************
// 4. Parsing the file, generate the Char Values and calculating the
// loveRatio. The result is appended to outputString
// ********************************************************************************************************************

try {
executionroutine(scanner, inputlength);
} catch (Throwable myException) {
executionroutine(scanner, inputlength);
} finally {
scanner.close();

}
}

public static int nthquersumme(int x) {
int y = x;
while (y >= 10) {
y = quersumme(y);
}
return y;
}

public static int quersumme(int x) {
int sum = 0;
while (x > 0) {
sum += x % 10;
x /= 10;
}
return sum;
}

public static void executionroutine(Scanner scanner, int inputlength) {
String loversString[][][] = new String[inputlength][inputlength][inputlength];
int loversInt[][][] = new int[inputlength][inputlength][inputlength];

String outputString = "";

while (scanner.hasNext()) {
for (int i = 0; i < inputlength; i++) {
for (int j = 0; j <= 1; j++) {
loversString[i][j][0] = scanner.next();
loversString[i][j][0] = loversString[i][j][0].toUpperCase();

int tmp_length = loversString[i][j][0].length();

// 4.1 Generate a temporary Char Array for each string in
// loversString[i][j][0]

char tmp_loverschar[] = new char[tmp_length + 1];
loversString[i][j][0].getChars(0, tmp_length,
tmp_loverschar, 0);

// 4.2 Clean chars, all chars other than a - z are set to 0,
// each char value is added to loversInt[i][j][1]

for (int k = 0; k < tmp_length; k++) {

int t[] = new int[tmp_length + 1];

if (1 <= ((int) tmp_loverschar[k] - 64)
&& ((int) tmp_loverschar[k] - 64) <= 26) {
t[k] = (int) tmp_loverschar[k] - 64;
} else {
t[k] = 0;
}

loversInt[i][j][1] = loversInt[i][j][1] + t[k];
}
}

// Calculate the loveRatio
double loveRatio1 = nthquersumme(loversInt[i][0][1]);
double loveRatio2 = nthquersumme(loversInt[i][1][1]);

double loveRatioof1and2 = 0;

if (loveRatio1 > loveRatio2) {
loveRatioof1and2 = loveRatio2 / loveRatio1;
} else {
loveRatioof1and2 = loveRatio1 / loveRatio2;
}

DecimalFormat df = new DecimalFormat("#.00 \u0025");

// Store the love Ratio
outputString = df.format(loveRatioof1and2) + "\n";

// Print Loveratio
System.out.println(outputString);
}

}
}

}

2.

/**
* Angewandte Mathematik, SS11
* Problem: 10424 - Love Calculator
* http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1365
* @author Sebastian Stumpf
* @author Benjamin Vogt
* @version 1.0, 2011-03-26 20:56:59
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.124
*/

import java.util.*;
import java.text.*;

public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
while(scanner.hasNextLine())
{
String name1 = scanner.nextLine();
String name2 = scanner.nextLine();
if(name1.isEmpty() || name2.isEmpty())
break;
if(name1.length()<=25 && name2.length()<=25)
{
name1 = (name1.replaceAll("[^a-zA-Z]", "")).toLowerCase();
name2 = (name2.replaceAll("[^a-zA-Z]", "")).toLowerCase();
int sum1 = 0;
int sum2 = 0;
int temp = 0;
for(int i=0; i<name1.length(); i++)
{
sum1 += (name1.charAt(i) - 96);
}
while(true)
{
temp += sum1%10;
sum1 /= 10;
if(sum1 == 0 && temp <=9)
{
sum1 = temp;
temp = 0;
break;
}
else if(sum1 == 0)
{
sum1 = temp;
temp = 0;
}
}
for(int i=0; i<name2.length(); i++)
{
sum2 += (name2.charAt(i) - 96);
}
while(true)
{
temp += sum2%10;
sum2 /= 10;
if(sum2 == 0 && temp <=9)
{
sum2 = temp;
temp = 0;
break;
}
else if(sum2 == 0)
{
sum2 = temp;
temp = 0;
}
}
DecimalFormat df = new DecimalFormat("#0.00 %");
String sdf = df.format(sum1<=sum2?((double)sum1/sum2):((double)sum2/sum1));
System.out.println(sdf.replaceAll(",", "."));
}
}
}
}

3.

/**
* Angewandte Mathematik, SS11
* Problem: 10424 Love Calculator
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1365
*
* @author Benedikt Z¨nnchen
* @author Erik Wenzel
* @version 1.0, 03/24/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.120
*/

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main
{

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
float checkSum1;
float checkSum2;
float result;

while(sc.hasNextLine())
{
checkSum1 = getDigitChecksum(getSum(sc.nextLine()));
checkSum2 = getDigitChecksum(getSum(sc.nextLine()));
result = 0;

// Anzeigevorbereitung (runden)
if (checkSum1 > checkSum2)
{
result = (checkSum2 / checkSum1) * 10000;
}
else
{
result = (checkSum1 / checkSum2) * 10000;
}
DecimalFormat df = new DecimalFormat("0.00");
String s = df.format((float) Math.round(result) / 100);

System.out.println(s + " %");
}
sc.close();
}

/**
* return the sum of the characters (a-z) of the name a=1, A=1, b=2, B=2 ...
*
* @param name
* @return sum
*/
public static int getSum(String name)
{
name = name.toLowerCase();
int sum = 0;
for (int i = 0; i < name.length(); i++)
{
char c = name.charAt(i);
if (c <= 'z' && c >= 'a')
{
sum += (c - 'a' + 1);
}
}
return sum;
}

/**
* return the checksum of the number
* @param number
* @return result checksum
*/
public static int getDigitChecksum(int number)
{
int result = 0;
while (number != 0)
{
result += (number % 10);
number = number / 10;
}

if (result >= 10)
{
return getDigitChecksum(result);
}
return result;
}
}

4.


/**
* Angewandte Mathematik, SS11
* Problem: 10424 Love Calculator
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&page=show_problem&problem=2113
*
* @author Schramm, Felix
* @author Vogel, Johannes
* @version 1.0, 03/21/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.124
*/

import java.util.*;

public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
while(scanner.hasNextLine()){
String name1 = scanner.nextLine();
String name2 = scanner.nextLine();
int sum1 = nameToSum(name1);
int sum2 = nameToSum(name2);
double ratio = (double)quersumme(sum1)/quersumme(sum2);
if(ratio>1)
ratio = 1/ratio;
System.out.printf("%.2f %%%n",ratio*100);
}
}


public static int nameToSum(String name){
int sum = 0;
for(int i=0;i<name.length();i++)
sum += charToInt(name.charAt(i));
return sum;
}


public static int charToInt(char letter){
if (letter>='a'&&letter<='z')
return letter-'a'+1;
else if (letter>='A'&&letter<='Z')
return letter-'A'+1;
else return 0;
}

static int quersumme(int number) {
while(number>9){
int quer = 0;
while(number!=0){
quer+=number%10;
number/=10;
}
number=quer;
}
return number;
}
}

5.



/**


 * Angewandte Mathematik, SS11


 * Problem: 10424 Love Calculator



 *


 * @author Christopher Westerfield


 * @version 1.0, 03/20/2011


 *


 * Method : Ad-Hoc


 * Status : Accepted


 * Runtime: 0.100


 */


 

import java.util.Scanner;


import java.io.*;


  


class Main


{


    public static void main(String[] args){


        Scanner scanner = new Scanner(System.in);


        String a = scanner.next();


        String b = scanner.next();


        char[] One = a.toCharArray();


        char[] Two = b.toCharArray();


        int res1 = 0;


        int res2 = 0;


        int tmp =0;


        for(int i=0;i<One.length;i++){


            tmp = Integer.parseInt(""+One[i],36) -9;


            res1 += tmp;


        }


        for(int i=0;i<Two.length;i++){


            tmp = Integer.parseInt(""+Two[i],36) - 9;


            res2 += tmp;


        }


        a = String.valueOf(res1);


        while(a.length()>1){


            res1 = 0;


            One = a.toCharArray();


            for(int i=0;i<One.length;i++){


                tmp = Integer.parseInt(""+One[i]);


                res1 += tmp;


            }


            a = String.valueOf(res1);


        }


        b = String.valueOf(res2);


        while(b.length()>1){


            res2 = 0;


            Two = b.toCharArray();


            for(int i=0;i<Two.length;i++){


                tmp = Integer.parseInt(""+Two[i]);


                res2 += tmp;


            }


            b = String.valueOf(res2);


        }


        double result;


        if((double)res2<0.004 || (double)res2>-0.004){


            result = 100.00;


        }else{


            result = (double)res1 / (double)res2;


            if(result>=1.0){


                result = (double)res2/(double)res1;


            }


            result *= 10000;


            result = (double)(Math.round(result))/(double)100;


        }


        System.out.println(String.valueOf(result)+" %");


    }


}






------------------------------------------------------------------------------------------------

1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 10424 Love Calculator
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1365
*
* @author Fabian Liebl
* @version 1.0, 10/06/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.104
*/

import java.io.*;

public class Main {

private static int getValue(String s) {
int value = 0;
char c;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if ((c >= 'a') && (c <= 'z'))
{
value += c - 96;
}
if ((c >= 'A') && (c <= 'Z')) {
value += c - 64;
}
}
return value;
}

private static int getCrossSum(int i) {
int x = i;
int value = 0;
while (x > 0) {
value += x % 10;
x = x / 10;
}
return value;
}

public static void main(String[] args) throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));

String name1, name2;
int name1Value, name2Value;
double love;

while (true) {
name1 = inputReader.readLine();
if (name1 == null) {
// EOF
return;
}
name2 = inputReader.readLine();

name1Value = getValue(name1);
name2Value = getValue(name2);

while (name1Value > 9) {
name1Value = getCrossSum(name1Value);
}
while (name2Value > 9) {
name2Value = getCrossSum(name2Value);
}

if (name1Value > name2Value) {
love = (double) name2Value / (double) name1Value;
} else {
love = (double) name1Value / (double) name2Value;
}

System.out.printf("%.2f %%\n", love*100);
}
}

}