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(); } } |
分類: Java
Java – UVA10008
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 |
import java.util.Scanner; /** * UVA10008 */ public class UVA10008 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String temp = sc.nextLine(); temp = temp.replace(" ", ""); int num = Integer.parseInt(temp); int[] count = new int[26]; int max = 0; for (int i = 0; i < num; i++) { temp = sc.nextLine().toLowerCase(); for (int j = 0; j < temp.length(); j++) { if (temp.charAt(j) <= 122 && temp.charAt(j) >= 97) { count[temp.charAt(j) - 97]++; if (count[temp.charAt(j) - 97] > max) max = count[temp.charAt(j) - 97]; } } } for (int i = max; i > 0; i--) for (int j = 0; j < count.length; j++) { if (i == count[j]) System.out.println((char) (j + 65) + " " + count[j]); } sc.close(); } } |
Java – UVA490
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.ArrayList; import java.util.List; import java.util.Scanner; /** * UVA490 */ public class UVA490 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); List<String> input = new ArrayList<String>(); int max = 0; int maxLine = 0; while (sc.hasNextLine()) { String temp = sc.nextLine(); input.add(temp); if (max <= temp.length()) { max = temp.length(); maxLine = input.size() - 1; } } for (int i = 0; i < max; i++) { for (int j = input.size() - 1; j >= 0; j--) { String temp = input.get(j); if (temp.length() > i) System.out.print(temp.charAt(i)); else if (j > maxLine) System.out.print(" "); } System.out.println(); } sc.close(); } } |
Java – UVA272
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; /** * UVA272 */ public class UVA272 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean symbol = false; while (sc.hasNextLine()) { String temp = sc.nextLine(); for (int i = 0; i < temp.length(); i++) { if (temp.charAt(i) == '\"') { if (!symbol) System.out.print("<code></code>"); else System.out.print("\'\'"); symbol = !symbol; } else System.out.print(temp.charAt(i)); } System.out.println(); } sc.close(); } } |
Java 2018-04-18 HW
檔案下載
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 46 47 48 49 50 |
/** * CDogKind */ class CDogKind { String Kind, Name; int age; void show() { System.out.println("寵物種類:" + Kind); } } /** * CDog */ class CDog extends CDogKind { CDog(String Kind, String Name, int age) { this.Kind = Kind; this.Name = Name; this.age = age; } void setAge(int age) { this.age = age; } void setName(String Name) { this.Name = Name; } void show() { super.show(); System.out.println("寵物名子:" + this.Name); System.out.println("寵物年齡:" + this.age); } } /** * Java_2018_04_18_HW * Author:Dragonyue */ public class Java_2018_04_18_HW { public static void main(String[] args) { CDog myDog = new CDog("柯基", "小昌弟弟", 3); myDog.show(); } } |
Java 2018-04-11 HW2
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; /** * Java_2018_04_11_HW2 * Author:Dragonyue */ public class Java_2018_04_11_HW2 { public static void main(String[] args) { // TODO 自動產生的方法 Stub Scanner scanner = new Scanner(System.in); System.out.print("輸入:"); int num = Integer.parseInt(scanner.nextLine()); for (int i = 0; i < num; i++) { for (int j = 0; j <= i; j++) { System.out.print(PSC(i, j) + " "); } System.out.println(); } } public static int PSC(int r, int c) { if (r == c || c == 0) return 1; else return PSC(r - 1, c) + PSC(r - 1, c - 1); } } |
Jav 2018-04-11 HW1
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 46 47 48 49 50 51 52 53 54 |
import java.util.Scanner; /** * Java_2018_04_11_HW1 * Author:Dragonyue */ class A { int SN; String Name; A() { System.out.println("111"); } A(int SN) { this(); System.out.println("222"); this.SN = SN; } void setName(String Name) { this.Name = Name; } String getName() { return this.SN + "\r\n" + this.Name; } void A(String str) { System.out.print("1個" + str); } void A(String num, String str) { int n = Integer.parseInt(num); System.out.print(num + "個" + str); } } public class Java_2018_04_11_HW1 { public static void main(String[] args) { A aA = new A(333); aA.setName("Howhow"); System.out.println(aA.getName()); Scanner scanner = new Scanner(System.in); String[] str = scanner.nextLine().split(" "); if (str.length == 1) aA.A(str[0]); else if (str.length == 2) aA.A(str[0], str[1]); } } |
Java 2018-03-28 HW
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
import java.util.*; /** * Java_2018_03_28_HW * Author:Dragonyue */ class Record { int Data = -1; Record nextRecord; public Record(int Data) { this.Data = Data; } public static void ShowData(Record record) { while (record.nextRecord != null) { System.out.print(record.Data + " "); record = record.nextRecord; } System.out.println(record.Data); } public static Record Insert(Record aRecord, int input, List<Record> records) { Record firstRecord = aRecord; if (input <= aRecord.Data) { Record temp = new Record(input); temp.nextRecord = aRecord; records.add(aRecord); return temp; } Record lastrRecord = null; while (aRecord.Data <= input) { lastrRecord = aRecord; if (aRecord.nextRecord != null) aRecord = aRecord.nextRecord; else break; } Record newRecord = new Record(input); records.add(newRecord); if (lastrRecord.nextRecord != null) newRecord.nextRecord = lastrRecord.nextRecord; else newRecord.nextRecord = null; lastrRecord.nextRecord = newRecord; return firstRecord; } public static void Revise(Record aRecord, int nowvalue, int newValue) { while (aRecord.nextRecord != null) { if (aRecord.Data == nowvalue) aRecord.Data = newValue; aRecord = aRecord.nextRecord; } if (aRecord.Data == nowvalue) aRecord.Data = newValue; } public static Record Delete(Record aRecord, int Value, List<Record> records) { if (aRecord == null) { System.out.println("資料為空!"); return null; } Record firstRecord = aRecord; Record lastRecord = null; if (aRecord.Data == Value) { Record nextRecord = aRecord.nextRecord; if (records.indexOf(aRecord) != -1) records.remove(aRecord); firstRecord = nextRecord; return firstRecord; } while (aRecord.nextRecord != null) { lastRecord = aRecord; if (aRecord.nextRecord.Data == Value) { lastRecord.nextRecord = aRecord.nextRecord.nextRecord; records.remove(aRecord.nextRecord); return firstRecord; } else aRecord = aRecord.nextRecord; } return firstRecord; } public static void Append(Record aRecord, int input, List<Record> records) { while (aRecord.nextRecord != null) aRecord = aRecord.nextRecord; Record newRecord = new Record(input); aRecord.nextRecord = newRecord; records.add(newRecord); } } public class Java_2018_03_28_HW { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Record aRecord = null; int method; int input; List<Record> records = new ArrayList<>(); while (true) { System.out.print("輸入(0:離開 1:插入 2:修改 3:刪除:4:新增):"); method = scanner.nextInt(); if (method == 0) break; else if (method == 1) { System.out.print("輸入新增的值:"); input = scanner.nextInt(); if (aRecord == null) aRecord = new Record(input); else { aRecord = Record.Insert(aRecord, input, records); } } else if (method == 2) { System.out.print("請輸入要修改的值與新的值(ex 12 3):"); int nowvalue = scanner.nextInt(); int newValue = scanner.nextInt(); Record.Revise(aRecord, nowvalue, newValue); } else if (method == 3) { System.out.print("請輸入要刪除的值:"); input = scanner.nextInt(); aRecord = Record.Delete(aRecord, input, records); } else if (method == 4) { input = scanner.nextInt(); if (aRecord != null) Record.Append(aRecord, input, records); else aRecord = new Record(input); } if (aRecord != null) Record.ShowData(aRecord); } } } |