發表文章

目前顯示的是 11月, 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 { 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

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 w || tempy > h) { if(!drop_loc[x][y]) { drop_loc[x][y] = true; drop = true; break; } } else { x = tempx; y = tempy; } } } if(drop) { System.out.printf("%d %d %c LOST\r\n", x, y, ori); } else System.out.printf("%d %d %c\r\n", x, y, ori); } } };

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

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

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 = 0 && map[i - 1][j] == '*') count++; if( i + 1 = 0 && map[i][j - 1] == '*') count++; if( j + 1 = 0 && j - 1 >= 0 && map[i - 1][j - 1] == '*') count++; if( i - 1 >= 0 && j + 1 = 0 && map[i + 1][j - 1] == '*') count++; if( i + 1

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

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

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 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 = m || y >= n || datas[x][y] != datas[x1][y1]) { flag = false; break; } } if(!flag) break; } if(!flag) break; } System.out.println(i * 2 - 1); } } } };

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 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

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

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 0) { int temp = numtemp % j; numtemp /= j; total[j] += bases[temp]; } if(total[j]

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 max) max = freq[c]; } for(int i = 1; i = 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

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

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

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 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 = 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 = '0' && c = 'A' && c = 'a' && c max) max = r; } for(int i = max; i

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