huaweibishi

This commit is contained in:
zeek 2020-03-01 21:25:27 +08:00
parent b10b3613ff
commit dc3061d010
7 changed files with 270 additions and 1 deletions

2
.gitignore vendored
View File

@ -3,4 +3,4 @@
*.class
.idea
java/.idea
java/target

View File

@ -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<String> list = new ArrayList<String>();
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;
}
}

View File

@ -29,6 +29,7 @@ public class HeChangDui {
System.out.println(total - ret);
}
br.close();
}
private static int[] calculate(int[] data) { // max[i]存储最长子序列长度为i的时候,最小的序列结尾.

113
java/bishi/HePai.java Normal file
View File

@ -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<Character, Integer> 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<Character, Integer> map){
Map<Character, Integer> mapBak = null;
for (Map.Entry<Character, Integer> 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<Character, Integer> map){
Character pre = null;
int lianxu = 0;
int preCiShu = 0;
for (int i=0;i<nums.length;i++){
Character c = nums[i];
Integer num = map.get(c);
if (num == null){
continue;
}
if (num == 3 || num == 0){
map.remove(c);
pre = null;
lianxu = 0;
preCiShu = 0;
continue;
}
if (pre == null){
pre = c;
lianxu +=1;
preCiShu = num;
map.remove(c);
continue;
}
if (preCiShu != num){
return false;
}
if (c - pre > 1){
return false;
}
pre = c;
lianxu += 1;
map.remove(c);
if (lianxu == 3){
pre = null;
lianxu = 0;
preCiShu = 0;
}
}
return map.size() == 0;
}
}

39
java/bishi/StrSorted.java Normal file
View File

@ -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<str.length();j++){
char sc=str.charAt(j);
if(c==sc||c==sc-32){
builder.append(sc);
}
}
}
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
if(!(c>='a'&&c<='z')&&!(c>='A'&&c<='Z')){
builder.insert(i,c);
}
}
System.out.println(builder.toString());
}
bf.close();
}
}

55
java/bishi/SuShuZuHe.java Normal file
View File

@ -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<Long> evens = new ArrayList<Long>();
List<Long> odds = new ArrayList<Long>();
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()<odds.size()){
System.out.println(evens.size());
}
else{
System.out.println(odds.size());
}
}
// 3.得到从偶数集合和奇数集合各抽取一个数字组成素数的最大组合数
}
}
}

View File

@ -16,6 +16,7 @@ public class YueSeFuHuan {
}
count(numList, m, 1, numList.size());
}
in.close();
}
private static void count(Map<Integer, Integer> numList, int m, int step, int maxSize){