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; /** * UVA11461 */ public class UVA11461 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { double n1 = sc.nextDouble(), n2 = sc.nextDouble(); if (n1 == 0 && n2 == 0) break; int count = 0; for (double i = n1; i <= n2; i++) { String Sqrt = String.valueOf(Math.sqrt(i)); String temp = Sqrt.substring(Sqrt.indexOf(".") + 1, Sqrt.length()); if (temp.length() == 1) count++; } System.out.println(count); } sc.close(); } } |
月份: 2018 年 5 月
Java – UVA11063
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 31 32 33 34 35 36 |
import java.util.Arrays; import java.util.Scanner; /** * UVA11063 */ public class UVA11063 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = 0; while (sc.hasNext()) { String str = sc.next(); if (str.equals("EOF")) break; count++; int n = Integer.parseInt(str); int[] num = new int[n]; for (int i = 0; i < n; i++) num[i] = sc.nextInt(); boolean flag = true; for (int i = 0; i < num.length - 1; i++) { int sum = num[i] + num[i + 1]; for (int j = 0; j < num.length; j++) if (sum == num[j]) { flag = false; break; } if (flag == false) break; } System.out.printf("Case #%d: It is%s a B2-Sequence.\r\n", count, flag ? "" : " not"); } sc.close(); } } |
Java – UVA10931
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; /** * UVA10931 */ public class UVA10931 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int num = sc.nextInt(); if (num == 0) break; String bin = Integer.toBinaryString(num); int binFreq = 0; for (int i = 0; i < bin.length(); i++) if (bin.charAt(i) == '1') binFreq++; System.out.printf("The parity of %s is %d (mod 2).\r\n", bin, binFreq); } sc.close(); } } |
Java – UVA10093
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 31 32 33 34 35 36 |
import java.util.Scanner; /** * UVA10093 */ public class UVA10093 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextLine()) { String str = sc.nextLine(); char[] c = str.toCharArray(); int sum = 0, max = 1, temp = 0; for (int i = 0; i < c.length; i++) { if (c[i] >= 48 && c[i] <= 57) temp = c[i] - 48; else if (c[i] >= 65 && c[i] <= 90) temp = c[i] - 65 + 10; else if (c[i] >= 97 && c[i] <= 122) temp = c[i] - 97 + 10 + 26; sum += temp; if (temp > max) max = temp; } for (int i = max; i <= 62; i++) { if (sum % i == 0) { System.out.println(i + 1); break; } else if (i == 62) { System.out.println("such number is impossible!"); } } } sc.close(); } } |
Java – UVA10071
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import java.util.Scanner; /** * UVA10071 */ public class UVA10071 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n1 = sc.nextInt(), n2 = sc.nextInt(); System.out.println(n1 * n2 * 2); } sc.close(); } } |
Java – UVA10019
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; /** * UVA10019 */ public class UVA10019 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); for (int i = 0; i < count; i++) { int num = sc.nextInt(); String bin = Integer.toBinaryString(num); int hexNum = Integer.parseInt(Integer.toString(num), 16); String hex = Integer.toBinaryString(hexNum); int binFreq = 0, hexFreq = 0; for (int j = 0; j < bin.length(); j++) if (bin.charAt(j) == '1') binFreq++; for (int j = 0; j < hex.length(); j++) if (hex.charAt(j) == '1') hexFreq++; System.out.printf("%d %d\r\n", binFreq, hexFreq); } sc.close(); } } |
Java – UVA948
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 31 32 33 34 35 36 37 38 39 40 |
import java.util.ArrayList; import java.util.Scanner; /** * UVA948 */ public class UVA948 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); for (int j = 0; j < count; j++) { int n = sc.nextInt(); int N = n; ArrayList<Integer> intList = new ArrayList<Integer>(); intList.add(1); if (n >= 1) { intList.add(2); int temp = 0; while (temp <= n) { temp = intList.get(intList.size() - 2) + intList.get(intList.size() - 1); intList.add(temp); } } String fib = ""; for (int i = intList.size() - 2; i >= 0; i--) { int get = intList.get(i); if (n >= get) { n -= get; fib += "1"; } else fib += "0"; } if (N == 1) fib = "1"; System.out.printf("%d = %s (fib)\r\n", N, fib); } sc.close(); } } |
Java – UVA10783
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import java.util.Scanner; /** * UVA10783 */ public class UVA10783 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int time = sc.nextInt(); for (int i = 0; i < time; i++) { int n1 = sc.nextInt(), n2 = sc.nextInt(), sum = 0; for (int j = n1; j <= n2; j++) if ((j & 0x00000001) == 1) sum += j; System.out.printf("Case %d: %d\r\n", i + 1, sum); } sc.close(); } } |