1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import java.util.Scanner; /** * UVA10268 */ public class UVA10268 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextLine()) { int x = Integer.parseInt(sc.nextLine()); String[] str = sc.nextLine().split(" "); int[] intArray = new int[str.length]; int sum = 0; for (int i = 0; i < intArray.length; i++) intArray[i] = Integer.parseInt(str[i]); for (int i = 0; i < intArray.length - 1; i++) sum += intArray[i] * (intArray.length - 1 - i) * Math.pow(x, intArray.length - 2 - i); System.out.println(sum); } sc.close(); } } |
Java – UVA10170
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.util.Scanner; /** * UVA10170 */ public class UVA10170 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { long S = sc.nextLong(), D = sc.nextLong(); for (long i = S; i < D; i += S) S++; System.out.println(S); } sc.close(); } } |
Java – UVA10056
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import java.util.Scanner; /** * UVA10056 */ public class UVA10056 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int time = sc.nextInt(); for (int i = 0; i < time; i++) { double n1 = sc.nextDouble(); double p = sc.nextDouble(); double n2 = sc.nextDouble(); System.out.printf("%.4f\r\n", p == 0 ? p : p * Math.pow(1 - p, n2 - 1) / (1 - Math.pow(1 - p, n1))); } sc.close(); } } |
Java – UVA10038
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import java.util.Arrays; import java.util.Scanner; /** * UVA10038 */ public class UVA10038 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextLine()) { int time = sc.nextInt(); int[] intArray = new int[time]; for (int i = 0; i < intArray.length; i++) intArray[i] = sc.nextInt(); int[] d = new int[intArray.length - 1]; for (int i = 0; i < d.length; i++) d[i] = Math.abs(intArray[i] - intArray[i + 1]); Arrays.sort(d); boolean flag = true; for (int i = 0; i < time - 1; i++) if (d[i] != i + 1) flag = false; System.out.printf("%s\r\n", flag ? "Jolly" : "Not jolly"); } sc.close(); } } |
Java – UVA12019
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.util.Scanner; /** * UVA12019 */ public class UVA12019 { public static void main(String[] args) { String days[] = new String[] { "", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", }; Scanner sc = new Scanner(System.in); int n [] = new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31}; int num = sc.nextInt(); for (int i = 0; i < num; i++) { int day = 0; int m = sc.nextInt() , d = sc.nextInt(); for(int j = m - 1 ; j >= 1 ; j--) day += n[j]; day += d; int thisday = day % 7; System.out.println(days[thisday]); } sc.close(); } } |
Java – UAV11332
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import java.util.Scanner; /** * UVA11332 */ public class UVA11332 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String temp = ""; while (sc.hasNext()) { temp = sc.nextLine(); if (temp.equals("0")) break; String s = g(temp); System.out.println(s); } } public static String g(String str) { if (str.length() <= 1) return str; else { int sum = 0; for (int i = 0; i < str.length(); i++) sum += Integer.parseInt(str.substring(i, i + 1)); return g(Integer.toString(sum)); } } } |
Java – UVA10252
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import java.util.Scanner; /** * UVA10252 */ public class UVA10252 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] n1, n2; while (sc.hasNextLine()) { String str1 = sc.nextLine(), str2 = sc.nextLine(); n1 = new int[26]; n2 = new int[26]; for (int i = 0; i < str1.length(); i++) if (str1.charAt(i) >= 97 && str1.charAt(i) <= 122) n1[str1.charAt(i) - 97]++; for (int i = 0; i < str2.length(); i++) if (str2.charAt(i) >= 97 && str2.charAt(i) <= 122) n2[str2.charAt(i) - 97]++; for (int i = 0; i < 26; i++) { int min = Math.min(n1[i], n2[i]); for (int j = 0; j < min; j++) System.out.print((char) (i + 97)); } System.out.println(); } } } |
Java – UVA10222
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import java.util.Scanner; /** * UVA10222 */ public class UVA10222 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String chars = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./'"; String temp = null; while (sc.hasNextLine()) { temp = sc.nextLine().toLowerCase(); for (int i = 0; i < temp.length(); i++) { char c = temp.charAt(i); if (c == ' ') System.out.print(' '); else { int index = chars.indexOf(temp.charAt(i)); System.out.print(chars.charAt(index - 2)); } } System.out.println(); } sc.close(); } } |