Java 1.6.0 supported? YES!!!
Posted: Sat Sep 15, 2007 2:49 am
Congratulations!!
Java guys, Java 1.6.0 is supported on the new judge system.
We can really enjoy it.
Here is a sample code for p100.
I wonder it can be used to replace the old Java sample code on the website
http://acm.uva.es/p/data/p100.java.html
Special Note:
1. Your class name should be Main
2. Your class should be located in default package










Java guys, Java 1.6.0 is supported on the new judge system.
We can really enjoy it.

Here is a sample code for p100.
I wonder it can be used to replace the old Java sample code on the website
http://acm.uva.es/p/data/p100.java.html
Special Note:
1. Your class name should be Main
2. Your class should be located in default package
Code: Select all
import java.io.*;
import java.util.Scanner;
/**
* Problem 100: The 3n + 1 problem
*/
public class Main {
public static int cycleLength(long n) {
int count = 1;
while (n > 1) {
count++;
n = ((n & 1) == 0) ? (n >> 1) : (3 * n + 1);
}
return count;
}
public static void main(String[] args) throws IOException {
Scanner cin = new Scanner(System.in);
PrintStream cout = System.out;
while (cin.hasNextInt()) {
int a = cin.nextInt();
int b = cin.nextInt();
int maxCycleLen = 0;
int sIdx = Math.min(a, b);
int eIdx = Math.max(a, b);
for (int i = sIdx; i <= eIdx; i++) {
maxCycleLen = Math.max(maxCycleLen, cycleLength(i));
}
cout.printf("%d %d %d\n", a, b, maxCycleLen);
}
}
}