1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import java.util.Scanner; /** * UVA10929 */ public class UVA10929 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String str = sc.next(); if (str.equals("0")) break; boolean odd = true; int sum = 0; for (int i = str.length() - 1; i >= 0; i--) { sum += odd ? str.charAt(i) - '0' : -(str.charAt(i) - '0'); odd = !odd; } System.out.printf("%s is%s a multiple of 11.\r\n", str, sum % 11 == 0 ? "" : " not"); } sc.close(); } } |
日期: 2018 年 6 月 2 日
Java – UVA10420
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 |
import java.util.Arrays; import java.util.Scanner; /** * UVA10420 */ public class UVA10420 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int times = sc.nextInt(); sc.nextLine(); String[] country = new String[times]; for (int i = 0; i < times; i++) { country[i] = sc.next(); sc.nextLine(); } Arrays.sort(country); for (int i = 0; i < country.length;) { String index = country[i]; int count = 0; for (int j = 0; j < country.length; j++) if (country[j].equals(index)) { count++; i = j + 1; } System.out.printf("%s %d\r\n", index, count); } sc.close(); } } |
Java – UVA10101
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 41 42 43 44 45 |
import java.util.Scanner; /** * UVA10101 */ public class UVA10101 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int times = 1; while (sc.hasNext()) { System.out.printf("%4d.", times); long input = sc.nextLong(); if (input != 0) BanglaNumber(input); else System.out.printf(" 0"); System.out.printf("\r\n"); times++; } sc.close(); } public static void BanglaNumber(long input) { if (input >= 10000000) { BanglaNumber(input / 10000000); System.out.printf(" kuti"); BanglaNumber(input % 10000000); } else if (input >= 100000) { BanglaNumber(input / 100000); System.out.printf(" lakh"); BanglaNumber(input % 100000); } else if (input >= 1000) { BanglaNumber(input / 1000); System.out.printf(" hajar"); BanglaNumber(input % 1000); } else if (input >= 100) { BanglaNumber(input / 100); System.out.printf(" shata"); BanglaNumber(input % 100); } else if (input != 0) { System.out.printf(" %d", input); } } } |
Java – UVA10055
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import java.util.Scanner; /** * UVA10055 */ public class UVA10055 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { long n1 = sc.nextLong(), n2 = sc.nextLong(); System.out.println(Math.abs(n1 - n2)); } sc.close(); } } |
Java – UVA10041
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.Arrays; import java.util.Scanner; /** * UVA10041 */ public class UVA10041 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int times = sc.nextInt(); for (int i = 0; i < times; i++) { int count = sc.nextInt(); int[] num = new int[count]; for (int j = 0; j < num.length; j++) num[j] = sc.nextInt(); Arrays.sort(num); int sum = 0; for (int j = 0; j < num.length; j++) sum += Math.abs(num[j] - num[num.length / 2]); System.out.println(sum); } sc.close(); } } |
Java – UVA10035
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.*; /** * UVA10035 */ public class UVA10035 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n1 = sc.nextInt(), n2 = sc.nextInt(); if (n1 == 0 && n2 == 0) break; int times = 0; int carry = 0; while (n1 != 0 || n2 != 0) { int r1 = n1 % 10; int r2 = n2 % 10; carry = (r1 + r2 + carry) / 10; times += carry; n1 /= 10; n2 /= 10; } System.out.printf("%s carry operation%s.\r\n", times > 0 ? Integer.toString(times) : "No", times > 1 ? "s" : ""); } sc.close(); } }; |
Java – UVA100
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 |
import java.util.Scanner; import java.util.Arrays; /** * UVA100 */ public class UVA100 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long[] num = new long[2]; while (sc.hasNext()) { num[0] = sc.nextLong(); num[1] = sc.nextLong(); long start = num[0], end = num[1]; if (num[0] > num[1]) { start = num[1]; end = num[0]; } int max = 0; for (long i = start; i <= end; i++) { long n = i; int times = 0; while (n != 1) { if (n % 2 == 0) n /= 2; else n = 3 * n + 1; times++; } if (times + 1 > max) max = times + 1; } System.out.printf("%d %d %d\r\n", num[0], num[1], max); } sc.close(); } } |