發表文章

目前顯示的是 2020的文章

UVA 11321 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int num = sc.nextInt(); int m = sc.nextInt(); System.out.printf("%d %d\r\n", num, m); if(num == 0&& m == 0) break; Data[] datas = new Data[num]; for(int i = 0; i < num; i++) { int n = sc.nextInt(); datas[i] = new Data(n, n % m, n % 2 == 0); } Arrays.sort(datas); for(int i = 0; i < num; i++) { System.out.println(datas[i].toString()); } } } public static class Data implements Comparable { int n; int r; boolean even; Data(int n, int r, boolean even) { this.n = n; this.r = r; this.even = even; } public String toString() { return Integer.toString(this.n); } @Override public int compareTo(Data other) { if(this.r != other.r) return this.r < other.r ? -1 : 1

UVA 118 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int w = sc.nextInt(), h = sc.nextInt(); boolean drop_loc[][] = new boolean[51][51]; while(sc.hasNext()) { int x = sc.nextInt(), y = sc.nextInt(); char ori = sc.next().charAt(0); String cmd = sc.next(); boolean drop = false; for(int i = 0; i < cmd.length(); i++) { char c = cmd.charAt(i); int tempx = x; int tempy = y; if(c == 'L') { if(ori == 'N') ori = 'W'; else if(ori == 'E') ori = 'N'; else if(ori == 'S') ori = 'E'; else if(ori == 'W') ori = 'S'; } else if(c == 'R') { if(ori == 'N') ori = 'E'; else if(ori == 'E') ori = 'S'; else i

UVA 10415 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); for(int t = 0; t < cases; t++) { String finger[] = {"c0111001111", "d0111001110", "e0111001100", "f0111001000", "g0111000000", "a0110000000", "b0100000000", "C0010000000", "D1111001110", "E1111001100", "F1111001000", "G1111000000", "A1110000000", "B1100000000"}; String current = "00000000000"; String cmd = sc.next(); int[] count = new int[10]; for(int index = 0; index < cmd.length(); index++) { char c = cmd.charAt(index); for(int i = 0; i < 14; i++) { if(finger[i].charAt(0) == c) { String temp = finger[i]; for(int j = 1; j < 11; j++) { if(current.charAt(j)

UVA 10409 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int num = sc.nextInt(); if(num == 0) break; int top = 1, n = 2, w = 3, s = 5, e = 4; for(int i = 0; i < num; i++) { String cmd = sc.next(); if(cmd.equals("north")) { n = top; top = s; s = 7 - n; } else if(cmd.equals("east")) { e = top; top = w; w = 7 - e; } else if(cmd.equals("south")) { s = top; top = n; n = 7 - s; } else if(cmd.equals("west")) { w = top; top = e; e = 7 - w; } } System.out.println(top); } } };

UVA 10189 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t = 0, h = 0, w =0; while(sc.hasNextInt()) { h = sc.nextInt(); w = sc.nextInt(); if(h == 0 || w == 0) break; if(t != 0) System.out.println(); System.out.printf("Field #%d:\r\n", ++t); char[][] map = new char[h][w]; for(int i = 0; i < h; i++) { String str = sc.next(); for(int j = 0; j < w; j++) map[i][j] = str.charAt(j); } for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { int count = 0; if(map[i][j] == '*') System.out.print("*"); else { if( i - 1 >= 0 && map[i - 1][j] == '*') count++; if( i + 1 < h && map[i + 1][j] == '*') count++; if( j - 1 >= 0 &&

UVA 10057 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int n = sc.nextInt(); int[] datas = new int[n]; for(int i = 0; i < n; i++) datas[i] = sc.nextInt(); Arrays.sort(datas); int mid = datas[(n - 1) / 2]; int mid2 = datas[n / 2]; int count = 0; for(int i = 0; i < n; i++) if(datas[i] == mid || datas[i] == mid2) count++; System.out.printf("%d %d %d\r\n", mid, count, mid2 - mid + 1); } } };

UVA 10242 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextDouble()) { double[] px = new double[4]; double[] py = new double[4]; double x = 0, y = 0; for(int i = 0; i < 4; i++) { px[i] = sc.nextDouble(); py[i] = sc.nextDouble(); x += px[i]; y += py[i]; } for(int i = 0; i < 4; i++) for(int j = i + 1; j < 4; j++) if(px[i] == px[j] && py[i] == py[j]) { System.out.printf("%.3f %.3f\r\n", x - px[i] * 3, y - py[i] * 3); i = j = 4; } } } };

UVA 229 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); for(int t = 0; t < cases; t++) { int n = sc.nextInt(); int[] datas = new int[n]; for(int i = 0; i < n; i++) datas[i] = sc.nextInt(); int count = 0; for(int i = 0; i < n-1; i++) for(int j = 0; j < n-1; j++) { if(datas[j] > datas[j+1]) { int temp = datas[j+1]; datas[j+1] = datas[j]; datas[j] = temp; count++; } } System.out.printf("Optimal train swapping takes %d swaps.\r\n", count); } } };

UVA 10221 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int r = 6440; while(sc.hasNextInt()) { double s = (double)sc.nextInt(); double a = (double)sc.nextInt(); String str = sc.next(); if(str.equals("deg")) a = Math.min(360-a, a); else a /= 60; double arc= 2*Math.PI*(s+r)*a/360; double chord = Math.sqrt(2*Math.pow(s+r, 2)*(1-Math.cos(a*Math.PI/180))); System.out.printf("%.6f %.6f\r\n", arc, chord); } } };

UVA 10908 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); for(int t = 0; t < cases; t++) { int m = sc.nextInt(); int n = sc.nextInt(); int q = sc.nextInt(); System.out.printf("%d %d %d\r\n", m, n, q); char[][] datas = new char[m][n]; for(int i = 0; i < m; i++) { String str = sc.next(); for(int j = 0; j < n; j++) datas[i][j] = str.charAt(j); } for(int k = 0; k < q; k++) { int x1 = sc.nextInt(); int y1 = sc.nextInt(); int i; for(i = 0; i < m; i++) { boolean flag = true; for(int x = x1 - i; x <= x1 + i; x++) { for(int y = y1 - i; y <= y1 + i; y++) { if(x < 0 || y < 0 || x >= m || y >= n || datas[x][y] != datas[x1][y1]) { flag = false; break;

UVA 10922 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLine()) { String input = sc.nextLine(); if(input.equals("0")) break; String str = input; int count = str.equals("9") ? 1 : 0; while(str.length() != 1) { int sum = 0; for(int i = 0; i < str.length(); i++) sum += str.charAt(i) - '0'; if(sum % 9 == 0) count ++; else break; str = Integer.toString(sum); } if(count > 0) System.out.printf("%s is a multiple of 9 and has 9-degree %d.\r\n", input, count); else System.out.printf("%s is not a multiple of 9.\r\n", input); } } };

UVA 10190 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLong()) { long n = sc.nextLong(); long m = sc.nextLong(); boolean flag = m == 1 ? false : true; List num = new ArrayList (); while(flag) { num.add(n); if(n == 1) break; else if(n % m == 0) n /= m; else { flag = false; break; } } if(flag) { for(int i = 0; i < num.size(); i++) { System.out.print(num.get(i)); if(i != num.size() - 1) System.out.print(" "); } System.out.println(); } else System.out.println("Boring!"); } } };

UVA 10050 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); for(int t = 0; t < cases; t++) { int n = sc.nextInt(); int h = sc.nextInt(); int[] party = new int[h]; for(int i = 0; i < h; i++) party[i] = sc.nextInt(); int count = 0; for(int i = 1; i < n + 1; i++) { boolean flag = false; for(int j = 0; j < h; j++) if(i % party[j] == 0) flag = true; if(flag && i % 7 != 0 && i % 7 != 6) count++; } System.out.println(count); } } };

UVA 11005 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); for(int i = cases; i > 0; i--) { System.out.printf("Case %d:\r\n", cases -i +1); int[] bases = new int[36]; for(int j = 0; j < 36; j++) bases[j] = sc.nextInt(); int changes = sc.nextInt(); for(int k = 0; k < changes; k++) { int min = Integer.MAX_VALUE; int num = sc.nextInt(); int[] total = new int[37]; for(int j = 2; j < 37; j++) { int numtemp = num; while(numtemp > 0) { int temp = numtemp % j; numtemp /= j; total[j] += bases[temp]; } if(total[j] < min) min = total[j]; } System.out.printf("Cheapest base(s) for number %d:", num); for(int j=2; j < 37; j++) if(min == total[j]) System.out.print("

UVA 10062 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int newline = 0; while(sc.hasNextLine()) { String str = sc.nextLine(); if(newline++ !=0) System.out.println(); int[] freq = new int[127]; int max = 0; for(int i = 0; i < str.length(); i++) { char c = str.charAt(i); if(++freq[c] > max) max = freq[c]; } for(int i = 1; i <= max; i++) for(int j = 126; j >= 0; j--) if(freq[j] == i) System.out.printf("%d %d\r\n", j, i); } } };

UVA 11417 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int num; while((num = sc.nextInt()) != 0) { int gcd = 0; for(int i = 1; i < num; i++) for(int j = i+1; j <= num; j++) { int num1 = i, num2 = j; while(num2 != 0) { int temp = num2; num2 = num1 % num2; num1 = temp; } gcd += num1; } System.out.println(gcd); } } };

UVA 10193 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = Integer.parseInt(sc.nextLine()); for(int i = 0; i < cases; i++) { int num1 = Integer.parseInt(sc.nextLine(), 2); int num2 = Integer.parseInt(sc.nextLine(), 2); while(num2 != 0) { int temp = num2; num2 = num1 % num2; num1 = temp; } if(num1 != 1) System.out.printf("Pair #%d: All you need is love!\r\n", i + 1); else System.out.printf("Pair #%d: Love is not all you need!\r\n", i + 1); } } };

UVA 10641 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int n = sc.nextInt(); if(n == 0) break; String str = Integer.toBinaryString(n); int count = 0; for(int i = 0; i < str.length(); i++) if(str.charAt(i) == '1') count++; System.out.printf("The parity of %s is %d (mod 2).\r\n", str, count); } } };

UVA 948 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); for(int i = 0; i < cases; i++) { int n = sc.nextInt(); List fib = new ArrayList (); fib.add(1); if(n > 1) { fib.add(2); int temp = fib.get(fib.size()-1) + fib.get(fib.size()-2); while(temp <= n) { fib.add(temp); temp = fib.get(fib.size()-1) + fib.get(fib.size()-2); } } String str = String.format("%d = ", n); for(int j = fib.size() - 1; j >= 0; j--) { if(n >= fib.get(j)) { str+="1"; n -= fib.get(j); } else str += "0"; } System.out.printf("%s (fib)\r\n", str); } } };

UVA 10071 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int v = sc.nextInt(); int t = sc.nextInt(); System.out.println(v * t * 2); } } };

UVA 10093 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLine()) { String str = sc.nextLine(); int sum = 0; int max = 1; int r = 0; for(int i =0; i < str.length(); i++) { char c = str.charAt(i); if(c >= '0' && c <= '9') r = c - '0'; else if(c >= 'A' && c <= 'Z') r = c - 'A' + 10; else if(c >= 'a' && c <= 'z') r = c - 'a' + 36; sum += r; if(r > max) max = r; } 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!"); } } } };

UVA 11461 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int num1 = sc.nextInt(); int num2 = sc.nextInt(); if(num1 == num2 && num1 == 0) break; int count = (int)Math.sqrt(num2) - (int)Math.ceil(Math.sqrt(num1)) + 1; System.out.println(count); } } };

UVA 10235 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int n = sc.nextInt(); boolean P_n = checkPrime(n); String str = Integer.toString(n); int n2 = 0; for(int i = 0; i < str.length();i++) n2 += (str.charAt(i) - '0') * Math.pow(10, i); boolean P_n2 = checkPrime(n2); if(!P_n) System.out.printf("%d is not prime.\r\n", n); else if(P_n && ! P_n2 || n == n2) System.out.printf("%d is prime.\r\n", n); else System.out.printf("%d is emirp.\r\n", n); } } public static boolean checkPrime(int num) { for(int i = 2; i <= num / 2; i++) if(num % i == 0) return false; return true; } };

UVA 11349 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); sc.nextLine(); for(int times = 0; times < cases; times++) { String[] str = sc.nextLine().split(" "); int lines = Integer.parseInt(str[str.length - 1]); int[] input = new int[lines * lines]; for(int i = 0; i < lines; i++) { String line = sc.nextLine().trim(); String[] temp =line.split(" "); for(int j = 0; j < temp.length; j++) input[i * lines + j] = Integer.parseInt(temp[j]); } boolean check = true; for(int i = 0; i < input.length / 2; i++) if(input[i] != input[input.length-1-i] || input[i] < 0) { check = false; break; } System.out.printf("Test #%d: %s\r\n", times + 1, check ? "Symmetric." : "Non-symmetric."); } } };

UVA 10812 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); for(int i = 0; i < cases; i++) { int num1 = sc.nextInt(); int num2 = sc.nextInt(); int sum = num1 + num2; int dif = num1 - num2; if(sum < 0 || dif < 0 || sum % 2 != 0 && dif % 2 != 0) System.out.println("impossible"); else System.out.printf("%d %d\r\n", sum / 2, dif / 2); } } };

UVA 10170 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { long p = sc.nextLong(); long d = sc.nextLong(); long s = p; while(s < d) s += ++p; System.out.println(p); } } };

UVA 10056 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = sc.nextInt(); for(int i =0; i < cases; i++) { int n = sc.nextInt(); double p = sc.nextDouble(); int l = sc.nextInt(); System.out.printf("%.4f\r\n", p == 0 ? p : (p * Math.pow(1-p, l-1))/(1 - Math.pow(1-p, n))); } } };

UVA 12019 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int[] mon = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; int cases = sc.nextInt(); for(int i =0; i < cases; i++) { int m = sc.nextInt(); int d = sc.nextInt(); d += 4; for(int j = 1; j < m; j++) d = d + mon[j-1]; System.out.println(days[d%7]); } } };

UVA 10252 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLine()) { String str1 = sc.nextLine().toLowerCase(); String str2 = sc.nextLine().toLowerCase(); int[] count1 = new int[26]; int[] count2 = new int[26]; for(int i = 0; i < str1.length(); i++) { char c = str1.charAt(i); if(c>='a' && c <= 'z') count1[c - 'a']++; } for(int i = 0; i < str2.length(); i++) { char c = str2.charAt(i); if(c >= 'a' && c <= 'z') count2[c - 'a']++; } for(int i = 0; i < 26; i++) if(count1[i] != 0 && count2[i] != 0) { int min = Math.min(count1[i], count2[i]); for(int j = 0; j < min; j++) System.out.print((char)(i + 'a')); } System.out.println(); } } };

UVA 100 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int num1 = sc.nextInt(); int num2 = sc.nextInt(); int max_n = Math.max(num1, num2); int min_n = Math.min(num1, num2); int max = 0; for(int i = min_n; i <= max_n; i++) { int n = i; int count = 1; while(n != 1) { count++; if(n%2 == 1) n=3*n+1; else n = n / 2; } if(count > max) max = count; } System.out.printf("%d %d %d\r\n", num1, num2, max); } } };

UVA 11063 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cases = 0; while(sc.hasNextInt()) { int input = sc.nextInt(); if(input >= 2 && input <= 100) { cases++; int[] datas = new int[input]; List sum = new ArrayList (); for(int i = 0; i < input; i++) datas[i] = sc.nextInt(); boolean check = true; for(int i = 0; i < input; i++) for(int j = 0; j < input; j++) if(i <= j) { int temp = datas[i] + datas[j]; if(sum.indexOf(temp) == -1) sum.add(temp); else { check = false; break; } } if(check) System.out.printf("Case #%d: It is a B2-Sequence.\r\n", cases); else System.out.printf("Case #%d: It is not a B2-Sequence.\r\n", cases); } } } };

UVA 10101 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int count = 0; while(sc.hasNextLong()) { long num = sc.nextLong(); System.out.printf("%4d.", ++count); if(num == 0) System.out.print(" 0"); else bangla(num); System.out.println(); } } public static void bangla(long num) { if(num >= 10000000) { bangla(num / 10000000); System.out.print(" kuti"); num = num % 10000000; } if(num >= 100000) { bangla(num / 100000); System.out.print(" lakh"); num = num % 100000; } if(num >= 1000) { bangla(num / 1000); System.out.print(" hajar"); num = num % 1000; } if(num >= 100) { bangla(num / 100); System.out.print(" shata"); num = num % 100; } if(num > 0) System.out

UVA 272 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); boolean check = true; while(sc.hasNextLine()) { String str = sc.nextLine(); for(int i=0; i < str.length(); i++) { char c = str.charAt(i); if(c == '\"') { System.out.print(check ? "``" : "\'\'"); check = !check; } else System.out.print(c); } System.out.println(); } } };

UVA 11332 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLine()) { String str = sc.nextLine(); if(str.equals("0")) break; while(str.length() > 1) { int num = 0; for(int i = 0; i < str.length(); i++) num += str.charAt(i) - '0'; str = Integer.toString(num); } System.out.println(str); } } }; import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextLine()) { int num = Integer.parseInt(sc.nextLine()); if(num == 0) break; while(num >= 10) { int temp = 0; while(num != 0) { temp += num % 10; num /= 10; } num = temp; } System.out.println(num); } } };

UVA 490 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int max = 0; List inputs = new ArrayList (); while(sc.hasNextLine()) { String str = sc.nextLine(); if(str.length() > max) max = str.length(); inputs.add(str); } Collections.reverse(inputs); for(int j = 0; j < max; j++) { int count = 0; for(int i = 0; i < inputs.size(); i++) { String str = inputs.get(i); if(j < str.length()) { while(count > 0) { System.out.print(" "); count--; } System.out.print(str.charAt(j)); count = 0; } else count++; } System.out.println(); } } };

UVA 10019 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int lines = sc.nextInt(); for(int i =0; i < lines; i++) { String input = Integer.toString(sc.nextInt()); String bin_str = Integer.toBinaryString(Integer.parseInt(input)); int count1 = 0; for(int j = 0; j < bin_str.length(); j++) if(bin_str.charAt(j) == '1') count1 ++; String hex_to_dec_str = Integer.toBinaryString(Integer.parseInt(input, 16)); int count2 = 0; for(int j = 0; j < hex_to_dec_str.length(); j++) if(hex_to_dec_str.charAt(j) == '1') count2 ++; System.out.println(String.format("%d %d", count1, count2)); } } };

UVA 10035 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int num1 = sc.nextInt(); int num2 = sc.nextInt(); if(num1 == 0 && num2 ==0) break; else { int count = 0; int temp = 0; while(num1 != 0 || num2 !=0) { int n1 = num1 % 10; int n2 = num2 % 10; temp = temp + n1 + n2; if(temp >= 10) count ++; temp /= 10; num1 /= 10; num2 /= 10; } if(count == 0) System.out.println("No carry operation."); else if(count == 1) System.out.println("1 carry operation."); else System.out.println(String.format("%d carry operations.", count)); } } } };

UVA 10008 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int lines = sc.nextInt(); sc.nextLine(); int[] count = new int[26]; int max = 0; for(int i = 0; i < lines; i++) { String str = sc.nextLine().toLowerCase(); for(int j = 0; j < str.length(); j++) { char ch = str.charAt(j); if(ch >= 97 && ch <= 122) if(++count[ch - 97] > max) max = count[ch - 97]; } } for(int i = max; i > 0; i--) for(int j = 0; j < 26; j++) if(i == count[j]) System.out.println(String.format("%c %d", (char)(j + 65), i)); } };

UVA 10420 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int lines = sc.nextInt(); sc.nextLine(); String[] datas = new String[lines]; for(int i = 0; i < lines; i++) { String[] str = sc.nextLine().split(" "); datas[i] = str[0]; } Arrays.sort(datas); for(int i = 0; i < lines; i++) { String search = datas[i]; int count = 0; for(int j = i; j < lines; j++) { if(datas[j].equals(search)) { count ++; i = j; } else break; } System.out.println(String.format("%s %d", search, count)); } } };

UVA 10222 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); String decode = "qwertyuiop[]asdfghjkl;'zxcvbnm,./"; while(sc.hasNextLine()) { String str = sc.nextLine().toLowerCase(); for(int i = 0; i < str.length(); i++) { char c = str.charAt(i); int index = decode.indexOf(c) - 2; if(c == ' ') System.out.print(" "); else System.out.print(decode.charAt(index)); } System.out.println(); } } };

UVA 10038 Java

import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int size = sc.nextInt(); boolean is_jolly = true; if(size != 1) { int[] input = new int[size]; for(int i = 0; i < size; i++) input[i] = sc.nextInt(); int[] dif = new int[size -1]; for(int i = 0; i < size-1; i++) dif[i] = Math.abs(input[i+1] - input[i]); Arrays.sort(dif); for(int i = 0; i < size-1; i++) if(dif[i] != i+1) { is_jolly = false; break; } } else sc.nextInt(); if(is_jolly) System.out.println("Jolly"); else System.out.println("Not jolly"); } } };

UVA 11150 Java

import java.util.*; import static java.lang.System.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int n = sc.nextInt(); System.out.println(n + n / 2); } } };

UVA 10783 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int times = sc.nextInt(); for(int i = 0; i < times; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int sum = 0; for(int j = a; j <= b; j++) if(j % 2 != 0) sum += j; System.out.println(String.format("Case %d: %d", i+1, sum)); } } };

UVA 10268 Java

import java.util.*; public class main{ 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(" "); //System.out.println(x); int output = 0; for(int i = 0; i < str.length - 1; i++) { int n = Integer.parseInt(str[i]); output += n * Math.pow(x, str.length -2 -i) * (str.length -1 -i); } System.out.println(output); } } };

UVA 10929 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNextLine()) { String str = sc.nextLine(); if(str.equals("0")) return; int odd=0, even=0; for(int i = 0; i < str.length(); i++) { if(i % 2 == 0) //even += Integer.parseInt(String.valueOf(str.charAt(i))); even += str.charAt(i) - 48; else //odd += Integer.parseInt(String.valueOf(str.charAt(i))); odd += str.charAt(i) - 48; } if(Math.abs(odd-even)%11 == 0) System.out.println(str + " is a multiple of 11."); else System.out.println(str + " is not a multiple of 11."); } } };

UVA 10055 Java

import java.util.*; public class main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { long n1 = sc.nextLong(); long n2 = sc.nextLong(); System.out.println(Math.abs(n1 - n2)); } } };

UVA 10041 Java

import java.util.*; public class main{ 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[] datas = new int[count]; for(int j = 0; j < count; j++) datas[j] = sc.nextInt(); Arrays.sort(datas); int len = 0; for(int j = 0; j < count; j++) len += Math.abs(datas[j] - datas[j/2]); System.out.println(len); } } };