Created
November 2, 2011 01:08
-
-
Save mejibyte/1332550 to your computer and use it in GitHub Desktop.
Solution skeletons for problems in http://contests.factorcomun.org/contests/22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Main { | |
public static void main(String [] args) { | |
Scanner cin = new Scanner(System.in); | |
int T = cin.nextInt(); | |
for (int c = 0; c < T; ++c) { | |
int n = cin.nextInt(); | |
int a[] = new int[n]; | |
for (int i = 0; i < n; ++i) { | |
a[i] = cin.nextInt(); | |
} | |
// Aquí se leyeron todos los números y se guardaron en el arreglo a. | |
// Calcular la respuesta y guardarla en la variable answer. | |
double answer; | |
System.out.printf(Locale.US, "%.3f%%\n", answer); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
class Main { | |
public static void main(String [] args) { | |
Scanner cin = new Scanner(System.in); | |
PrintStream cout = System.out; | |
int T = cin.nextInt(); | |
for (int c = 1; c <= T; ++c) { | |
int a = cin.nextInt(); | |
int b = cin.nextInt(); | |
int sum = 0; | |
// Calcular aquí la suma de todos los impares entre a y b y guardarla en sum. | |
cout.printf("Case %d: %d\n", c, sum); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
class Main { | |
public static void main(String [] args) throws IOException { | |
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); | |
PrintStream cout = System.out; | |
while (true) { | |
String s = cin.readLine(); | |
if (s.equals("0:00")) break; | |
int hour = Integer.valueOf(s.split(":")[0]); | |
int minute = Integer.valueOf(s.split(":")[1]); | |
// Aquí se leyó la entrada y se tiene la hora en la variable hour y los minutos en la variabale minute. | |
// Con estos 2 datos, calcular la respuesta y guardarla en la variable answer. | |
double answer; | |
cout.printf("%.3f\n", answer); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
class Main { | |
public static void main(String [] args) { | |
Scanner cin = new Scanner(System.in); | |
PrintStream cout = System.out; | |
int set = 1; | |
while (true) { | |
int n = cin.nextInt(); | |
if (n == 0) break; | |
set++; | |
int h[] = new int[n]; | |
for (int i = 0; i < n; ++i) { | |
h[i] = cin.nextInt(); | |
} | |
// Aquí se leyeron todos los n números del caso y se guardaron en el arreglo h. | |
// Calcular la respuesta y guardarla en la variable answer | |
int answer; | |
cout.printf("Set #%d\nThe minimum number of moves is %d.\n\n", set++, answer); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
class Main { | |
public static void main(String [] args) { | |
Scanner cin = new Scanner(System.in); | |
PrintStream cout = System.out; | |
int ways[] = new int[7490]; | |
for (int i = 0; i < 7490; ++i) { | |
// Aquí calcular la respuesta para i y guardarla en ways[i] | |
// Ejemplo: ways[i] = número de maneras de formar i centavos | |
} | |
while (cin.hasNextInt()) { | |
int n = cin.nextInt(); | |
cout.println(ways[n]); // Simplemente imprimir la respuesta que ya habíamos calculado | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
class Main { | |
public static void main(String [] args) { | |
Scanner cin = new Scanner(System.in); | |
PrintStream cout = System.out; | |
long f[] = new long[51]; // Aquí tiene que ser long porque la respuesta es muy grande y no cabe en un int. | |
for (int i = 0; i <= 50; ++i) { | |
// Aquí calcular la respuesta para i y guardarla en f[i] | |
// Ejemplo: f[i] = respuesta | |
} | |
while (true) { | |
int n = cin.nextInt(); | |
if (n == 0) break; | |
cout.println(f[n]); // Simplemente imprimir la respuesta que ya habíamos calculado | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment