zoukankan      html  css  js  c++  java
  • 华为笔试——字符串关联系判断

    题目:忘了

    解析:

      1.首先判断给定的值是否合法,合法继续。

      2.根据给定值抽取出特殊字符串序列的特征值

      3.依次抽取出每个字符串的特征值与步骤2的特征值比较(直接使用jdk提供的方法)

    code:

     1 import java.util.*;
     2 
     3 public class Main {
     4     public static void main(String args[]){
     5         Scanner read = new Scanner(System.in);
     6         List<String> lists = new ArrayList<>();
     7         String speLine;
     8         int value=0;
     9         while(read.hasNext()){
    10             String line = read.nextLine();
    11             if(line.length()==1){
    12                 value = Integer.parseInt(line);
    13                 break;
    14             }
    15             lists.add(line);
    16         }
    17         speLine = read.nextLine();
    18         if(value<2 || value>9){
    19             for(int i=0;i<lists.size();i++){
    20                 System.out.println(lists.get(i));
    21             }
    22         }else{
    23 
    24             String s =getStr(speLine,value);
    25             for(int i=0;i<lists.size();i++){
    26                 String temp = getStr(lists.get(i),value);
    27                 /**
    28                  * 判断子串是否存在
    29                  */
    30                 if(s.length()<=temp.length() && temp.contains(s)){
    31                     System.out.println(lists.get(i));
    32                 }
    33             }
    34         }
    35 
    36     }
    37     //抽取每个字符串的特征值
    38     public static String getStr(String str,int value){
    39         StringBuffer buf = new StringBuffer();
    40         for(int i=0;i<str.length();i++){
    41             char c = str.charAt(i);
    42             if((c-'0')<value){
    43                 buf.append(c);
    44             }
    45         }
    46         return buf.toString();
    47     }
    48 
    49 }
    View Code
  • 相关阅读:
    一月5日
    一月4日
    Servlet API中forward()与redirect()的区别
    get和post的区别
    java短信验证码实现
    mybatis框架
    springMVC框架
    spring框架
    redis
    MySQL多表查询
  • 原文地址:https://www.cnblogs.com/dream-flying/p/13628929.html
Copyright © 2011-2022 走看看