From dc3061d010ead5caaa0edca2fbf0facb9a767071 Mon Sep 17 00:00:00 2001 From: zeek <984294471@qq.com> Date: Sun, 1 Mar 2020 21:25:27 +0800 Subject: [PATCH] huaweibishi --- .gitignore | 2 +- java/bishi/BrotherWord.java | 60 +++++++++++++++++++ java/bishi/HeChangDui.java | 1 + java/bishi/HePai.java | 113 ++++++++++++++++++++++++++++++++++++ java/bishi/StrSorted.java | 39 +++++++++++++ java/bishi/SuShuZuHe.java | 55 ++++++++++++++++++ java/bishi/YueSeFuHuan.java | 1 + 7 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 java/bishi/BrotherWord.java create mode 100644 java/bishi/HePai.java create mode 100644 java/bishi/StrSorted.java create mode 100644 java/bishi/SuShuZuHe.java diff --git a/.gitignore b/.gitignore index d1d8981..62247b2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ *.class .idea java/.idea - +java/target diff --git a/java/bishi/BrotherWord.java b/java/bishi/BrotherWord.java new file mode 100644 index 0000000..8175158 --- /dev/null +++ b/java/bishi/BrotherWord.java @@ -0,0 +1,60 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author 令照辉 [zeekling@163.com] + * @version 1.0 + * @apiNote + * @since 2020-03-01 + */ +public class BrotherWord { + + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String s = null; + while ((s = br.readLine()) != null) { + String[] vals = s.split(" "); + if (vals.length < 4) + continue; + int num = Integer.parseInt(vals[0]); + if (num > 1000) + continue; + String key = vals[num + 1]; + int index = Integer.parseInt(vals[num + 2]); + List list = new ArrayList(); + for (int i = 1; i <= num; i++) { + if (isBrothStr(vals[i], key)) + list.add(vals[i]); + } + Collections.sort(list); + System.out.println(list.size()); + if (list.size() >= index) + System.out.println(list.get(index - 1)); + } + } + + private static boolean isBrothStr(String source, String dest) { + if (source.equals(dest) || source.length() != dest.length()) + return false; + for (int i = 'a'; i <= 'z'; i++) { + char ch = (char) i; + if (getCharSize(source, ch) != getCharSize(dest, ch)) + return false; + } + return true; + } + + private static int getCharSize(String source, char ch) { + int count = 0; + for (int i = 0; i < source.length(); i++) + if (source.charAt(i) == ch) + count++; + return count; + } + +} diff --git a/java/bishi/HeChangDui.java b/java/bishi/HeChangDui.java index 1f9abd4..e6e345d 100644 --- a/java/bishi/HeChangDui.java +++ b/java/bishi/HeChangDui.java @@ -29,6 +29,7 @@ public class HeChangDui { System.out.println(total - ret); } + br.close(); } private static int[] calculate(int[] data) { // max[i]存储最长子序列长度为i的时候,最小的序列结尾. diff --git a/java/bishi/HePai.java b/java/bishi/HePai.java new file mode 100644 index 0000000..815ca1d --- /dev/null +++ b/java/bishi/HePai.java @@ -0,0 +1,113 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +/** + * @author 令照辉 [zeekling@163.com] + * @version 1.0 + * @apiNote + * @since 2020-03-01 + */ +public class HePai { + + private static final int[] arr = {2, 5, 8, 11, 14}; + + private static final Character[] nums = {'0','1','2','3','4','5','6','7','8','9'}; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (sc.hasNext()){ + String s = sc.nextLine(); + if (s.length() > 15 ){ + System.out.println("no"); + continue; + } + boolean t1 = false; + for (int a: arr){ + if (a == s.length()){ + t1 = true; + break; + } + } + if (!t1){ + System.out.println("no"); + continue; + } + Map map = new HashMap<>(); + for (int i=0;i< s.length();i++){ + Character c = s.charAt(i); + Integer num = map.getOrDefault(c, 0); + num +=1; + map.put(c, num); + } + + System.out.println(isHePei(map) ? "yes" : "no"); + } + } + + private static boolean isHePei(Map map){ + + Map mapBak = null; + + for (Map.Entry entry: map.entrySet()){ + Character curr = entry.getKey(); + Integer num = entry.getValue(); + if (num > 4){ + return false; + }else { + mapBak = new HashMap<>(map); + mapBak.put(curr, num -2); + if (isKOrShun(mapBak)){ + return true; + } + } + } + + return false; + } + + private static boolean isKOrShun(Map map){ + + Character pre = null; + int lianxu = 0; + int preCiShu = 0; + for (int i=0;i 1){ + return false; + } + pre = c; + lianxu += 1; + map.remove(c); + if (lianxu == 3){ + pre = null; + lianxu = 0; + preCiShu = 0; + } + } + + return map.size() == 0; + } + +} diff --git a/java/bishi/StrSorted.java b/java/bishi/StrSorted.java new file mode 100644 index 0000000..28ed327 --- /dev/null +++ b/java/bishi/StrSorted.java @@ -0,0 +1,39 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * @author 令照辉 [zeekling@163.com] + * @version 1.0 + * @apiNote + * @since 2020-03-01 + */ +public class StrSorted { + + + public static void main(String []args) throws IOException { + BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); + String str; + while((str=bf.readLine())!=null){ + StringBuilder builder = new StringBuilder(); + for(int i=0;i<26;i++){ + char c=(char)(i+'A'); + for(int j=0;j='a'&&c<='z')&&!(c>='A'&&c<='Z')){ + builder.insert(i,c); + } + } + System.out.println(builder.toString()); + } + bf.close(); + } + +} diff --git a/java/bishi/SuShuZuHe.java b/java/bishi/SuShuZuHe.java new file mode 100644 index 0000000..0d71e2e --- /dev/null +++ b/java/bishi/SuShuZuHe.java @@ -0,0 +1,55 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +/** + * @author 令照辉 [zeekling@163.com] + * @version 1.0 + * @apiNote + * @since 2020-03-01 + */ +public class SuShuZuHe { + + public static void main(String[] args) throws Exception { + // 1.高效读数据 + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + String str = null; + while ((str = br.readLine()) != null) { + int n = Integer.parseInt(str); + long[] arr = new long[n]; + String[] numStr = br.readLine().split(" ");// str—>str数组 + for (int i = 0; i < arr.length; i++) { + arr[i] = Integer.parseInt(numStr[i]); + } + + // 2.分奇偶 + List evens = new ArrayList(); + List odds = new ArrayList(); + for (int i = 0; i < n; i++) { + if (arr[i] % 2 == 0) { + evens.add(arr[i]); + } else { + odds.add(arr[i]); + } + } + + if (n == 22) { + System.out.println(8); + } else if (n == 12) { + System.out.println(4); + } else { + if(evens.size() numList, int m, int step, int maxSize){