zoukankan      html  css  js  c++  java
  • 在一个字符串中搜索虽一个字符串

    public class ContinueWithLabelDemo {
        public static void main(String[] args) {

            String searchMe = "Look for a substring in me";
            String substring = "sub";
            boolean foundIt = false;

            int max = searchMe.length() - substring.length(); 

        test:
            for (int i = 0; i <= max; i++) {
                int n = substring.length();
                int j = i;
                int k = 0;
                while (n-- != 0) {
                    if (searchMe.charAt(j++) != substring.charAt(k++)) {
                        continue test;
                    }
                }   
                foundIt = true;
                break test;
            }
            System.out.println(foundIt ? "Found it" : "Didn't find it");
        }
    }

  • 相关阅读:
    Tinkoff Challenge
    Tinkoff Challenge
    Tinkoff Challenge
    Tinkoff Challenge
    整体二分
    树链剖分+LCT
    上下界网络流
    莫队
    可并堆
    bzoj_1033: [ZJOI2008]杀蚂蚁antbuster
  • 原文地址:https://www.cnblogs.com/elite-2012/p/3198269.html
Copyright © 2011-2022 走看看