• 华为OJ平台——字符串匹配


    题目描述:

      判断短字符串中的所有字符是否在长字符串中全部出现

    输入:

      输入两个字符串。

      第一个为短字符,第二个为长字符

    输出:  

      true  - 表示短字符串中所有字符均在长字符串中出现

      false - 表示短字符串中有字符在长字符串中没有出现

    思路:

      题目很简单,只需要判断短字符串中的每个字符是否在长字符串中出现即可,无需判断字符之间的顺序等等

     1 import java.util.Scanner;
     2 
     3 public class MatchString {
     4 
     5     public static void main(String[] args) {
     6         Scanner cin = new Scanner(System.in) ;    
     7         String shortStr = cin.next() ;
     8         String longStr = cin.next() ;
     9         cin.close() ;
    10         
    11         System.out.println(judgeMatch(shortStr,longStr)) ;
    12 
    13     }
    14 
    15     private static boolean judgeMatch(String shortStr, String longStr) {
    16         char temp ;
    17         boolean flag ;
    18         for(int i = 0 ; i < shortStr.length() ; i++){
    19             temp = shortStr.charAt(i) ;
    20             flag = false ;
    21             for(int j = 0 ; j < longStr.length() ; j++){
    22                 if(longStr.charAt(j) == temp){
    23                     flag = true ;
    24                     break ;
    25                 }
    26             }
    27             if(!flag){
    28                 return false ;
    29             }
    30         }
    31         
    32         return true ;
    33     }
    34 
    35 }
  • 相关阅读:
    bk.
    仅仅为了记录
    一个简单的Lua解释器
    Lua与C++相互调用
    Struts标签、Ognl表达式、el表达式、jstl标签库这四者之间的关系和各自作用
    OGNL表达式struts2标签“%,#,$”
    Java异常报错机制
    到底EJB是什么?
    Spring总结
    JSON(JavaScript Object Notation)
  • 原文地址:https://www.cnblogs.com/mukekeheart/p/5628029.html
Copyright © 2020-2023  润新知