package org.goro.uva.m;
import java.io.*;
import java.util.*;
public class BenderTwo {
public static int[][] table = {{9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9},
{2, 3, 1, 0, 4, 5},
{3, 2, 0, 1, 4, 5},
{4, 5, 2, 3, 1, 0},
{5, 4, 2, 3, 0, 1}};
public static String[] coder = {"+x", "-x", "+y", "-y", "+z", "-z"};
public static void main(String[] args) throws Exception {
// FileWriter writer = new FileWriter("output.out");
// BufferedWriter out = new BufferedWriter(writer);
StringBuilder sb = new StringBuilder();
Reader.init(System.in);
// Reader.init(new FileInputStream(new File("input.in")));
int lenght = Reader.nextInt();
while (lenght > 0) {
int pos = 0;
for (int i = 1; i < lenght; i++) {
String tmp = Reader.next();
if (tmp.charAt(0) != 'N') pos = doStuff(tmp, pos);
}
sb.append(decode(pos)).append("\n");
lenght = Reader.nextInt();
}
System.out.print(sb);
// out.write(sb.toString());
// out.close();
}
public static int encode(char sign, char axis) {
if(sign == '+') {
if(axis == 'x') return 0;
if(axis == 'y') return 2;
return 4;
}
if(axis == 'x') return 1;
if(axis == 'y') return 3;
return 5;
}
public static String decode(int num) {
return coder[num];
}
public static int doStuff(String temp, int wire) {
int val = encode(temp.charAt(0), temp.charAt(1));
return table[val][wire];
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
06/10/2013
11507 - Bender B. RodrÃguez Problem - Java
10919 - Prerequisites? - Java
package org.goro.uva.m;
import java.io.*;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.*;
public class Prerequisites {
public static char[] ch_name1 = new char[25];
public static char[] ch_name2 = new char[25];
public static void main(String[] args) throws Exception {
// Reader.init(new FileInputStream(new File("input.in")));
Reader.init(System.in);
StringBuilder sb = new StringBuilder();
int noOfCourses = Reader.nextInt();
int noOfCat;
while (noOfCourses > 0) {
noOfCat = Reader.nextInt();
int coursesTaken[] = new int[noOfCourses];
boolean isValid = true;
for(int i = 0; i < noOfCourses; i++) coursesTaken[i] = Reader.nextInt();
for(int i = 0; i < noOfCat; i++) {
int tempNoCourses = Reader.nextInt();
int mustHave = Reader.nextInt();
int validated = 0;
for(int j = 0; j < tempNoCourses; j++) {
int tempCurse = Reader.nextInt();
for (int k : coursesTaken) {
// System.out.println("Checking course: " + tempCurse + " k: " + k);
if (tempCurse == k) {
validated++;
break;
}
}
}
if(validated < mustHave) {
isValid = false;
// System.out.println("Valid: " + validated + " must have: " + mustHave);
}
}
if(isValid) sb.append("yes\n");
else sb.append("no\n");
noOfCourses = Reader.nextInt();
}
System.out.print(sb);
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
10424 - Love Calculator - Java
package org.goro.uva.m;
import java.io.*;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.*;
public class LoveCalculator {
public static char[] ch_name1 = new char[25];
public static char[] ch_name2 = new char[25];
public static void main(String[] args) throws Exception {
// InputStreamReader isr = new InputStreamReader(new FileInputStream(new File("input.in")));
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder("");
String name1;
String name2;
while ((name1 = br.readLine()) != null) {
name2 = br.readLine();
name1 = name1.toLowerCase();
name2 = name2.toLowerCase();
ch_name1 = name1.toCharArray();
ch_name2 = name2.toCharArray();
int val1 = calculate(ch_name1);
int val2 = calculate(ch_name2);
if(val1 < val2) {
val1 ^= val2;
val2 ^= val1;
val1 ^= val2;
}
float propo = 0;
if( val1 != 0 ) propo = (float)val2 / (float)val1;
propo *=100;
sb.append(round(propo, 2)).append(" %\n");
}
System.out.print(sb);
}
static public String round(double d, int ic) {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(ic);
nf.setMinimumFractionDigits(ic);
double tmp = Double.parseDouble((nf.format(d)).replaceAll(",", ".").replaceAll(" ", "") );
String temp = Double.toString(tmp);
if(temp.endsWith(".0")) return temp + "0";
else return temp;
}
public static int calculate(char[] arr) {
int retVal = 0;
for(int i = 0; i < arr.length; i++) {
if(arr[i] >= 'a' && arr[i] <= 'z') retVal += arr[i] - 'a' + 1;
}
return add(retVal);
// return retVal;
}
public static int add(int val) {
// System.out.println("running: " + val);
String tmp = Integer.toString(val);
// System.out.println("String: " + tmp + "lenght:" + tmp.length());
int retVal = 0;
for(int i = 0; i < tmp.length(); i++) {
retVal += (tmp.charAt(i) - '0');
// System.out.println(tmp.charAt(i));
}
// System.out.println("got: " + retVal);
if(retVal > 9) return add(retVal);
else return retVal;
}
}
10324 - Zeros and Ones - Java
package org.goro.uva.m;
import java.io.*;
import java.util.*;
public class ZerosAndOnes {
public static void main(String[] args) throws Exception {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder("");
int testCase = 1;
String line;
while ((line = br.readLine()) != null) {
sb.append("Case ").append(testCase).append(":\n");
testCase++;
int noOfCases = Integer.parseInt(br.readLine());
for (int j = 0; j < noOfCases; j++) {
String[] str = br.readLine().split(" ");
int val1 = Integer.parseInt(str[0]);
int val2 = Integer.parseInt(str[1]);
if (val1 > val2) {
val1 ^= val2;
val2 ^= val1;
val1 ^= val2;
}
boolean isValid = true;
if (val1 != val2) {
for (int i = val1; i < val2; i++) {
if (line.charAt(i) != line.charAt(i + 1)) {
isValid = false;
break;
}
}
}
if (isValid)
sb.append("Yes\n");
else
sb.append("No\n");
}
}
System.out.print(sb);
}
}
15/08/2013
10141 - Request for Proposal - Java
import java.io.*;
import java.util.*;
public class Request {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
int noOfRequirements = Reader.nextInt();
int noOfProposals = Reader.nextInt();
double minPrice;
int maxProposals;
int bestOffer;
for(int k = 1; noOfRequirements > 0; k++) {
String[] proposalName = new String[noOfProposals];
double[] proposalPrice = new double[noOfProposals];
int[] metReqs = new int[noOfProposals];
for (int i = 0; i < noOfRequirements; i++) {
Reader.reader.readLine();
}
minPrice = 0;
maxProposals = -1;
bestOffer = 0;
for (int i = 0; i < noOfProposals; i++) {
proposalName[i] = Reader.reader.readLine();
proposalPrice[i] = Reader.nextDouble();
metReqs[i] = Reader.nextInt();
for (int j = 0; j < metReqs[i]; j++) {
Reader.reader.readLine();
}
if (metReqs[i] > maxProposals) {
maxProposals = metReqs[i];
minPrice = proposalPrice[i];
bestOffer = i;
} else if (metReqs[i] == maxProposals && minPrice > proposalPrice[i]) {
minPrice = proposalPrice[i];
bestOffer = i;
}
}
System.out.println("RFP #" + k);
System.out.println(proposalName[bestOffer]);
noOfRequirements = Reader.nextInt();
noOfProposals = Reader.nextInt();
if(noOfRequirements != 0) System.out.println("");
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
661 - Blowing Fuses - Java
import java.io.*;
import java.util.*;
public class BlowingFuses {
public static void main(String[] args) throws Exception {
// FileWriter writer = new FileWriter("output.out");
// BufferedWriter out = new BufferedWriter(writer);
Reader.init(System.in);
// Reader.init(new FileInputStream(new File("input.in")));
int currentCase = 1;
int noOfDevices = Reader.nextInt();
int noOfOperations;
int capacity;
int currentConsumption;
int maxConsumption;
boolean[] devicesState;
int[] devicesConsumption;
int tempDevice;
boolean isDone;
while (noOfDevices != 0) {
System.out.println("Sequence " + currentCase);
currentConsumption = 0;
maxConsumption = 0;
noOfOperations = Reader.nextInt();
capacity = Reader.nextInt();
devicesState = new boolean[noOfDevices];
devicesConsumption = new int[noOfDevices];
isDone = false;
for(int i = 0; i < noOfDevices; i++) {
devicesConsumption[i] = Reader.nextInt();
devicesState[i] = false;
}
for(int i = 0; i < noOfOperations; i++) {
tempDevice = Reader.nextInt() - 1;
if(!devicesState[tempDevice]) {
//power on...
devicesState[tempDevice] = true;
currentConsumption += devicesConsumption[tempDevice];
if(currentConsumption > capacity) {
for(i = i + 1; i < noOfOperations; i++) Reader.nextInt();
System.out.println("Fuse was blown.\n");
isDone = true;
}
if(currentConsumption > maxConsumption) maxConsumption = currentConsumption;
} else {
//shutting down...
currentConsumption -= devicesConsumption[tempDevice];
devicesState[tempDevice] = false;
}
}
if(!isDone) {
System.out.println("Fuse was not blown.");
System.out.println("Maximal power consumption was " + maxConsumption + " amperes.\n");
}
noOfDevices = Reader.nextInt();
currentCase++;
}
// out.close();
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
11/08/2013
573 - The Snail - Java
package org.goro.uva.m;
import java.io.*;
import java.util.*;
public class TheSnail {
public static void main(String[] args) throws Exception {
// FileWriter writer = new FileWriter("output.out");
// BufferedWriter out = new BufferedWriter(writer);
try {
Reader.init(System.in);
// Reader.init(new FileInputStream(new File("input.in")));
while (true) {
int height = Reader.nextInt();
if(height == 0) break;
int dayDistance = Reader.nextInt();
int slidingDistance = Reader.nextInt();
int fatigueFactor = Reader.nextInt();
int dayLoss = fatigueFactor * dayDistance;
height *= 100;
dayDistance *= 100;
slidingDistance *= 100;
// out.write("DEBUG: New test case: H:" + height + " U:" + dayDistance + " D:" + slidingDistance + " F:" + fatigueFactor + " Loss:" + dayLoss);
int currentDay = 1;
int currentHeight = 0;
boolean isRunning = true;
while(isRunning) {
if(dayDistance > 0) {
currentHeight += dayDistance;
dayDistance -= dayLoss;
}
// out.write("DEBUG: Day:" + currentDay + " currHeight:" + currentHeight + "/" + height + " daySpeed: " + dayDistance + "\n");
if (currentHeight > height) {
System.out.println("success on day " + currentDay);
// out.write("success on day " + currentDay + "\n");
isRunning = false;
}
currentHeight -= slidingDistance;
if(currentHeight < 0 && isRunning) {
System.out.println("failure on day " + currentDay);
// out.write("failure on day " + currentDay + "\n");
isRunning = false;
}
currentDay++;
}
}
} catch (Exception ex) {
// ex.printStackTrace();
}
// out.close();
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
119 - Greedy Gift Givers - Java
import java.io.*;
import java.util.*;
public class GreedyGift {
public static void main(String[] args) throws Exception {
try {
Reader.init(System.in);
// Reader.init(new FileInputStream(new File("input.in")));
boolean isRunning = true;
boolean isFirst = true;
while (isRunning) {
int noOfPeoples = Reader.nextInt();
PeopleContainer cont = new PeopleContainer();
for (int i = 0; i < noOfPeoples; i++)
cont.addPeople(Reader.next());
for (int i = 0; i < noOfPeoples; i++) {
String gaverName = Reader.next();
int giftValues = Reader.nextInt();
int noOfGiven = Reader.nextInt();
if (noOfGiven == 0)
continue;
while (giftValues % noOfGiven != 0) {
giftValues--;
}
cont.addValue(gaverName, -giftValues);
if (noOfGiven != 0) {
int tempVal = giftValues / noOfGiven;
for (int j = 0; j < noOfGiven; j++) {
String getterName = Reader.next();
cont.addValue(getterName, tempVal);
}
}
}
if (!isFirst)
System.out.println("");
cont.printAll();
isFirst = false;
}
} catch (Exception ex) {
// ex.printStackTrace();
}
}
}
class People {
String name;
int val;
}
class PeopleContainer {
ArrayList<People> list;
PeopleContainer() {
list = new ArrayList<People>();
}
public void addPeople(String name) {
People pep = new People();
pep.name = name;
pep.val = 0;
list.add(pep);
}
public void addValue(String name, int value) {
Iterator it = list.iterator();
while (it.hasNext()) {
People tmp = (People) it.next();
if (tmp.name.equals(name)) {
tmp.val += value;
return;
}
}
}
public void printAll() {
Iterator it = list.iterator();
while (it.hasNext()) {
People tmp = (People) it.next();
System.out.println(tmp.name + " " + tmp.val);
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
12554 - A Special "Happy Birthday" Song!!! - Java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class HappyBirthday {
static String[] song = {"Happy", "birthday", "to", "you",
"Happy", "birthday", "to", "you",
"Happy", "birthday", "to", "Rujia",
"Happy", "birthday", "to", "you"
};
public static void main(String[] args) throws Exception {
Reader.init(System.in);
// Reader.init(new FileInputStream(new File("input.in")));
int noOfPeople = Reader.nextInt();
String[] peopleNames = new String[noOfPeople];
for(int i = 0; i < noOfPeople; i++) {
peopleNames[i] = Reader.next();
}
boolean isDone = false;
int i = 0;
// System.out.println("DEBUG: song lenght: " + song.length);
// System.out.println("DEBUG: noOfpeopne: " + noOfPeople);
while(!isDone) {
System.out.println(peopleNames[i%noOfPeople] + ": " + song[i%16]);
if(i%16 == 15 && i >= noOfPeople) isDone = true;
i++;
// System.out.println("*****DEBUG: song lenght: " + song.length);
// System.out.println("*****DEBUG: noOfpeopne: " + noOfPeople);
// System.out.println("******DEBUG Current song index: " + i%song.length + " current i:" + i);
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
12503 - Robot Instructions - Java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class RobotInstructions {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
// Reader.init(new FileInputStream(new File("input.in")));
int noOfTestCases = Reader.nextInt();
while((noOfTestCases--) > 0) {
int noOfInstructions = Reader.nextInt();
int currentPos = 0;
boolean[] instructions = new boolean[noOfInstructions];
for(int i = 0; i < noOfInstructions; i++) {
String currentInstruction = Reader.next();
if(currentInstruction.startsWith("L")) {
instructions[i] = false;
currentPos--;
} else if(currentInstruction.startsWith("R")) {
instructions[i] = true;
currentPos++;
} else {
Reader.next();
int tmp = Reader.nextInt();
instructions[i] = instructions[tmp-1];
if(instructions[i] == false) currentPos--;
else currentPos++;
}
}
System.out.println(currentPos);
}
}
}
///** Class for buffered reading int and double values */
///** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
12468 - Zapping - Java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Zapping {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
// Reader.init(new FileInputStream(new File("input.in")));
int a = Reader.nextInt();
int b = Reader.nextInt();
int val;
while(a >= 0 && b >= 0) {
val = Math.abs(a - b);
if(val > 50) val = 100 - val;
System.out.println(val);
a = Reader.nextInt();
b = Reader.nextInt();
}
}
}
///** Class for buffered reading int and double values */
///** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
10/08/2013
12157 - Tariff Plan - Java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class TariffPlan {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
//Reader.init(new FileInputStream(new File("input.in")));
int noOfTestCases = Reader.nextInt();
for(int i = 1; i <= noOfTestCases; i++) {
int noOfCalls = Reader.nextInt();
int mileTarifCost = 0;
int juiceTarifCost = 0;
int tempSeconds;
for(int j = 0; j < noOfCalls; j++) {
tempSeconds = Reader.nextInt();
//System.out.println("DEBUG: seconds / 30: " + ((tempSeconds/30) + 1));
mileTarifCost += (10 * (tempSeconds/30 + 1));
juiceTarifCost += (15 * (tempSeconds/60 + 1));
}
if(mileTarifCost < juiceTarifCost) {
System.out.println("Case " + i + ": Mile " + mileTarifCost);
} else if(mileTarifCost > juiceTarifCost) {
System.out.println("Case " + i + ": Juice " + juiceTarifCost);
} else {
System.out.println("Case " + i + ": Mile Juice "+ mileTarifCost);
}
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
12015 - Google is Feeling Lucky - Java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class GoogleLucky {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
//Reader.init(new FileInputStream(new File("file.in")));
int noOfTestCases = Reader.nextInt();
GoogleEntry[] sites = new GoogleEntry[10];
for(int i = 0; i < 10; i++) {
sites[i] = new GoogleEntry();
}
for(int i = 1; i <= noOfTestCases; i++) {
int currMax = 0;
System.out.println("Case #" + i + ":");
for(int j = 0; j < 10; j++) {
sites[j].webSite = Reader.next();
sites[j].rank = Reader.nextInt();
if(sites[j].rank > currMax) currMax = sites[j].rank;
}
for(int j = 0; j < 10; j++) {
if(sites[j].rank == currMax) System.out.println(sites[j].webSite);
}
}
}
}
class GoogleEntry {
public String webSite;
public int rank;
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
11942 - Lumberjack Sequencing - Java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class LumberjackSequencing {
enum Direction {undef, up, down};
public static void main(String[] args) throws Exception {
Reader.init(System.in);
//Reader.init(new FileInputStream(new File("input.in")));
int noOfTestCases = Reader.nextInt();
System.out.println("Lumberjacks:");
for(int i = 1; i <= noOfTestCases; i++) {
Direction dir = Direction.undef;
int previousVal;
int currentVal;
int j = 0;
boolean ordered = true;
previousVal = Reader.nextInt();
while(dir == Direction.undef && j < 9) {
currentVal = Reader.nextInt();
if(previousVal > currentVal) dir = Direction.down;
else if(previousVal < currentVal) dir = Direction.up;
j++;
previousVal = currentVal;
//System.out.println("DEBUG: Testcase " + i + "Dir: " + dir.toString() );
}
for(; j < 9; j++) {
currentVal = Reader.nextInt();
if(dir == Direction.down) {
//System.out.println("DEBUG: currJack: " + j + "Dir: " + dir.toString() + " curVal:" + currentVal + " prevVal:" + previousVal);
if(previousVal < currentVal) ordered = false;
} else if (dir == Direction.up) {
if(previousVal > currentVal) ordered = false;
}
previousVal = currentVal;
}
if(ordered) System.out.println("Ordered");
else System.out.println("Unordered");
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
11799 - Horror Dash - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class HorrorDash {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
int noOfTestCases = Reader.nextInt();
int noOfCreatures;
int max;
int currentSpeed;
for(int i = 1; i <= noOfTestCases; i++) {
noOfCreatures = Reader.nextInt();
max = 0;
for(int j = 0; j < noOfCreatures; j++) {
currentSpeed = Reader.nextInt();
if(currentSpeed > max) max = currentSpeed;
}
System.out.println("Case " + i + ": " + max);
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
11764 - Jumping Mario - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
//11764 - Jumping Mario
public class JumpingMario {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
int noOfTestCases = Reader.nextInt();
for(int currentCase = 1; currentCase <= noOfTestCases; currentCase++) {
int noOfWalls = Reader.nextInt() - 1;
int currentWall = Reader.nextInt();
int smallJumps = 0;
int bigJumps = 0;
while((noOfWalls--) > 0) {
int thisWall = Reader.nextInt();
if(thisWall < currentWall) {
smallJumps++;
} else if(thisWall > currentWall) {
bigJumps++;
}
currentWall = thisWall;
}
System.out.println("Case " + currentCase +": " + bigJumps + " " + smallJumps);
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
11679 - Sub-prime - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SubPrime {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
int noOfBanks = Reader.nextInt();
int noOfDebetures = Reader.nextInt();
int tempDebtor;
int tempCreditor;
int tempValue;
boolean flag;
while(noOfBanks != 0 && noOfDebetures != 0) {
int[] bankAccount = new int[noOfBanks];
for(int i = 0; i < noOfBanks; i++) {
bankAccount[i] = Reader.nextInt();
}
for(int i = 0; i < noOfDebetures; i++) {
tempDebtor = Reader.nextInt();
tempCreditor = Reader.nextInt();
tempValue = Reader.nextInt();
bankAccount[tempDebtor - 1] -= tempValue;
bankAccount[tempCreditor - 1] += tempValue;
}
flag = true;
for(int i = 0; i < noOfBanks; i++) {
if(bankAccount[i] < 0) {
flag = false;
break;
}
}
if(flag) System.out.println("S");
else System.out.println("N");
noOfBanks = Reader.nextInt();
noOfDebetures = Reader.nextInt();
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
11559 - Event Planning - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class EventPlanning {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int participants;
int budget;
int noOfHotels;
int noOfWeeks;
int bestCost;
String line;
while(true) {
boolean flag = false;
line = reader.readLine();
if(line == null || line.isEmpty()) break;
String[] vars = line.split(" ");
participants = Integer.parseInt(vars[0]);
budget = Integer.parseInt(vars[1]);
noOfHotels = Integer.parseInt(vars[2]);
noOfWeeks = Integer.parseInt(vars[3]);
int[] hotelCost = new int[noOfHotels];
bestCost = Integer.MAX_VALUE;
for(int i = 0; i < noOfHotels; i++) {
hotelCost[i] = Integer.parseInt(reader.readLine());
boolean validHotel = false;
line = reader.readLine();
String[] rooms = line.split(" ");
for(int j = 0; j < noOfWeeks; j++) {
if(Integer.parseInt(rooms[j]) >= participants) {
validHotel = true;
}
if(validHotel) {
if(bestCost > hotelCost[i]) bestCost = hotelCost[i];
flag = true;
}
}
}
if(flag) {
int sum = bestCost * participants;
if(sum <= budget) System.out.println(bestCost * participants);
else System.out.println("stay home");
}
else System.out.println("stay home");
}
}
}
11332 - Summing Digits - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SummingDigits {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
String line = "";
int sum;
while(!(line = Reader.next()).equals("0")) {
//System.out.println(line);
while(line.length() > 1) {
sum = 0;
for(int i = 0; i < line.length(); i++) {
sum += (line.charAt(i) - '0');
//System.out.println("DEBUG Sum = " + sum);
}
line = "" + sum;
}
System.out.println(line);
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
10963 - The Swallowing Ground - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SwallowingGround {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int noOfCases = Reader.nextInt();
int noOfColumns;
int x;
int y;
int maxGap;
boolean tempVal;
while((noOfCases--) > 0) {
noOfColumns = Reader.nextInt();
x = Reader.nextInt();
y = Reader.nextInt();
maxGap = Math.abs(x - y);
//System.out.println("DEBUG: " + Math.abs(x-y));
tempVal = true;
while((noOfColumns --) > 1) {
x = Reader.nextInt();
y = Reader.nextInt();
//System.out.println("DEBUG: " + Math.abs(x-y));
if(Math.abs(x - y) != maxGap) {
tempVal = false;
//break;
}
}
if(tempVal) System.out.println("yes");
else System.out.println("no");
if(noOfCases != 0) System.out.println("");
//tempVal = true;
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
10300 - Ecological Premium - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class EcologicalPremium {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int noOfCases = Reader.nextInt();
int noOfFarmers;
long size;
long degree;
long sum;
while((noOfCases--) > 0) {
sum = 0;
noOfFarmers = Reader.nextInt();
while((noOfFarmers --) > 0) {
size = Reader.nextInt();
Reader.nextInt();
degree = Reader.nextInt();
sum+=size*degree;
}
System.out.println(sum);
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
10114 - Loansome Car Buyer - Java
import java.io.*;
import java.util.StringTokenizer;
/*
* Your task is to write a program that calculates the first time,
* measured in months, that a car buyer owes less money than a
* car is worth. For this problem, depreciation is specified as
* a percentage of the previous month's value.
*/
public class loan {
//static String inputFilePath = "loan.in";
//static String outputFilePath = "loan.out";
public static void main(String[] args) throws IOException {
//InputStream inputStream = new FileInputStream(new File(inputFilePath));
//OutputStream outputStream = new FileOutputStream(new File(outputFilePath));
//Reader.init(inputStream);
Reader.init(System.in);
int loanDuration;
double downPayment;
double loanAmount;
double carValue;
int noOfDepr;
double monthlyPayment;
while((loanDuration = Reader.nextInt()) > 0) {
//System.out.println("New test case!");
downPayment = Reader.nextDouble();
loanAmount = Reader.nextDouble();
noOfDepr = Reader.nextInt();
monthlyPayment = loanAmount/loanDuration;
carValue = downPayment + loanAmount;
//System.out.println("Initial car value: " + carValue);
int readedDepr = 0;
int lastReadedDeprMonth = -1;
double lastReadedDeprValue = 0;
double monthDeprPercentage = 0;
int currentDepr = 0;
for(int currentMonth = 0; ; currentMonth++) {
if(readedDepr < noOfDepr && lastReadedDeprMonth < currentMonth) {
lastReadedDeprValue = monthDeprPercentage;
currentDepr = Reader.nextInt();
monthDeprPercentage = Reader.nextDouble();
readedDepr++;
lastReadedDeprMonth = currentDepr;
//System.out.println("DEBUG: readedDepr: " + readedDepr + " in month: " + currentMonth);
}
if(currentDepr > currentMonth) {
carValue -= carValue * lastReadedDeprValue;
} else {
carValue -= carValue * monthDeprPercentage;
}
//System.out.println("Doing work. month: " + currentMonth + " carVal: " + carValue + "loan:" + loanAmount);
if(carValue > loanAmount) {
//System.out.println("Month: " + currentMonth);
if(currentMonth == 1) {
//outputStream.write((currentMonth + " month\n").getBytes());
System.out.println(currentMonth + " month");
} else {
//outputStream.write((currentMonth + " months\n").getBytes());
System.out.println(currentMonth + " months");
}
//System.out.println("DEBUG: readedDepr: " + readedDepr + " deprs: " + noOfDepr);
while(readedDepr < noOfDepr) {
currentDepr = Reader.nextInt();
monthDeprPercentage = Reader.nextDouble();
readedDepr++;
//System.out.println("DEBUG: SKIPPED readedDepr: " + readedDepr + " deprs: " + noOfDepr);
}
break;
}
loanAmount -= monthlyPayment;
}
}
}
}
/* Class for buffered reading int and double values */
/* http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
621 - Secret Research - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SecretResearch {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
String line = "";
int noOfCases = Reader.nextInt();
for(int i = 0; i < noOfCases; i++) {
line = Reader.next();
if(line.equals("1") || line.equals("4") || line.equals("78")) System.out.println("+");
else if(line.endsWith("35")) System.out.println("-");
else if(line.startsWith("9") && line.endsWith("4")) System.out.println("*");
else if(line.startsWith("190")) System.out.println("?");
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
12577 - Hajj-e-Akbar - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class HajjeAkbar {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
String line="";
int noOfCase = 1;
while(!(line = Reader.next()).equals("*")) {
if(line.startsWith("H")) System.out.println("Case " + noOfCase + ": Hajj-e-Akbar");
else System.out.println("Case " + noOfCase + ": Hajj-e-Asghar");
noOfCase++;
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
12403 - Save Setu - Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SaveSetu {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
String line="";
int noOfCases = Reader.nextInt();
int total = 0;
for(int i = 0; i<noOfCases; i++) {
line = Reader.next();
if(line.startsWith("d")) {
total += Reader.nextInt();
} else if(line.startsWith("r")) {
System.out.println(total);
}
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
12372 - Packing for Holiday - Java
import java.util.Scanner;
public class PackingForHoliday {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int noOfCases = scan.nextInt();
int x, y, z;
for(int currentCase = 1; currentCase<=noOfCases; currentCase++) {
x = scan.nextInt();
y = scan.nextInt();
z = scan.nextInt();
if(x > 20) {
System.out.println("Case " + currentCase + ": bad");
continue;
}
if(y > 20) {
System.out.println("Case " + currentCase + ": bad");
continue;
}
if(z > 20) {
System.out.println("Case " + currentCase + ": bad");
continue;
}
System.out.println("Case " + currentCase + ": good");
}
}
}
12289 - One-Two-Three - Java
import java.util.Scanner;
//12289 - One-Two-Three - Java
public class OneTwoThree {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String line="";
int noOfCases = Integer.parseInt(scan.nextLine());
while((noOfCases--) > 0) {
line = scan.nextLine();
if(line.length() == 5) {
System.out.println("3");
continue;
}
if((line.charAt(0) == 'o' && line.charAt(1) == 'n') ||
(line.charAt(1) == 'n' && line.charAt(2) == 'e') ||
(line.charAt(2) == 'e' && line.charAt(0) == 'o'))
System.out.println("1");
else
System.out.println("2");
}
}
}
12279 - Emoogle Balance - Java
import java.util.Scanner;
// 12279 - Emoogle Balance - Java
public class EmoogleBalance {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int currentCase = 1;
int noOfCases;
int currentVal;
int total;
noOfCases = scanner.nextInt();
while(noOfCases != 0) {
total = 0;
for(int i = 0; i < noOfCases; i++) {
currentVal = scanner.nextInt();
if(currentVal == 0) total--;
else total ++;
}
System.out.println("Case " + currentCase + ": " + total);
noOfCases = scanner.nextInt();
currentCase++;
}
}
}
11727 - Cost Cutting - Java
import java.util.Scanner;
//11727 - Cost Cutting - Java
public class CostCutting {
static int testCases;
static int max;
static int min;
static int a;
static int b;
static int c;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
testCases = scanner.nextInt();
for(int i = 1; i < testCases+1; i++) {
a = scanner.nextInt();
b = scanner.nextInt();
c = scanner.nextInt();
System.out.print("Case " + i + ": ");
if (a > b) {
if (b > c) {
System.out.println(b);
continue;
}
if (a > c) {
System.out.println(c);
continue;
}
System.out.println(a);
continue;
}
if (a > c) {
System.out.println(a);
continue;
}
if (b > c) {
System.out.println(c);
continue;
}
System.out.println(b);
continue;
}
}
}
11547 - Automatic Answer - Java
import java.util.Scanner;
//11547
public class AutomaticAnswer {
static int testCases;
static String number = "";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
testCases = scanner.nextInt();
while((testCases--) != 0) {
number = Integer.toString((scanner.nextInt() * 315 + 36962)/10);
System.out.println(number.charAt(number.length() - 1));
}
scanner.close();
}
}
11498 - Division of Nlogonia - Java
import java.util.Scanner;
//11498
public class DivisionOfNlogonia {
static int noOfQueries;
static int divPtX;
static int divPtY;
static int ptX;
static int ptY;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while((noOfQueries = scanner.nextInt()) != 0) {
divPtX = scanner.nextInt();
divPtY = scanner.nextInt();
while((noOfQueries--) != 0) {
ptX = scanner.nextInt();
ptY = scanner.nextInt();
doWork();
}
}
}
public static void doWork() {
if(ptX == divPtX) {
System.out.println("divisa");
return;
}
if(ptY == divPtY) {
System.out.println("divisa");
return;
}
if(ptY > divPtY) {
if(ptX > divPtX) System.out.println("NE");
else System.out.println("NO");
return;
}
if(ptX > divPtX) System.out.println("SE");
else System.out.println("SO");
}
}
11364 - Parking - Java
11364 - Parking - Java
package org.goro.uva;
import java.util.Scanner;
//11364 - Parking
public class Parking {
static short testCases, shops;
static short min;
static short max;
static short val;
static Scanner scanner;
public static void main(String[] args) {
scanner = new Scanner(System.in);
testCases = scanner.nextShort();
while((testCases--) != 0) {
shops = scanner.nextShort();
min = 100;
max = 0;
while((shops--) != 0) {
val = scanner.nextShort();
if(val > max) max = val;
if(val < min) min = val;
}
System.out.println((max - min) * 2);
}
}
}
11172 - Relational Operator - Java
import java.util.Scanner;
public class RelationalOperator {
static int testCases;
static int a, b;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
testCases = scanner.nextInt();
for(int i = 0; i < testCases; i++) {
a = scanner.nextInt();
b = scanner.nextInt();
if(a > b) System.out.println(">");
else if(a < b) System.out.println("<");
else System.out.println("=");
}
scanner.close();
}
}
11044 - Searching for Nessy - Java
import java.util.Scanner;
//11044
public class SearchingForNessy {
static int testCases;
static int val1, val2;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
testCases = scanner.nextInt();
while((testCases--) != 0) {
val1 = scanner.nextInt();
val2 = scanner.nextInt();
val1 = val1/3;
val2 = val2/3;
System.out.println(val1 * val2);
}
scanner.close();
}
}
10550 - Combination Lock - Java
10550 - Combination Lock - Java
import java.util.Scanner;
//10550
public class CombinationLock {
static int val1, val2, val3, val4;
static int sum;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true) {
val1 = scanner.nextInt();
val2 = scanner.nextInt();
val3 = scanner.nextInt();
val4 = scanner.nextInt();
if((val1 == val2) && (val2 == val3) && (val3 == val4) && (val4 == 0)) break;
sum = val1 - val2;
if(val1 < val2) {
sum += 40;
}
sum += (val3 - val2);
if(val2 > val3) {
sum += 40;
}
sum += (val3 - val4);
if(val3 < val4) {
sum += 40;
}
System.out.println((sum + 120) * 9);
}
scanner.close();
}
}
1124 - Celebrity jeopardy - Java
1124 - Celebrity jeopardy - Java
import java.util.Scanner;
//1124
public class CelebrityJeopardy {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
System.out.println(scanner.nextLine());
}
scanner.close();
}
}
272 - TEX Quotes - Java
272 - TEX Quotes - Java
import java.util.Scanner;
//272 - TEX Quotes
public class TEXQuotes {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line;
boolean open = true;
boolean end = false;
while(scanner.hasNextLine()) {
line = scanner.nextLine();
for(int i = 0; i < line.length(); i++) {
if(line.charAt(i) == '\u001a'){
end = true;
break;
}
if(line.charAt(i) == '\"') {
if(open == true) {
System.out.print("``");
open = false;
continue;
} else {
System.out.print("''");
open = true;
continue;
}
}
System.out.print(line.charAt(i));
}
System.out.print("\n");
}
}
}
Subscribe to:
Posts (Atom)