Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Fall 2011 -- CSC 2700 Section 02

[Isaac's Home Page ]  [Mailing List ]  [Class Page ]  [Normal ]  

8/l/Rounders.java

import java.util.Scanner;
import java.math.*;
//* David Stewart
// ACM - ICPC Live Archive problem 3625
// Rounders
public class Rounders {
	
	public static void main(String args[]) {
	Scanner in = new Scanner(System.in);
	
	int counter, integer = 0;
	int[] digits = new int[9];
	String number = null;
	counter = in.nextInt();
	for (int i = 0; i < counter; i++) {
		integer = in.nextInt(); 
		number = Integer.toString(integer);
		for (int j = 0; j < number.length(); j++) {
			digits[j] = Integer.valueOf(String.valueOf(number.charAt(j)));
				}
		for (int j = number.length(); j > 0; j--) {
			if (digits[j] > 4 & j >= 1) {
				digits[j] = 0;
				digits[j-1] = digits[j-1] + 1;
			} else if (digits [j]  < 5 & j >= 1) {
				digits[j] = 0;
			} 
		}
		for (int j = 0; j < number.length(); j++) {
			
			System.out.print(digits[j]);
		}
		System.out.println();
	}
}		
}	

The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Isaac Traxler