zoukankan      html  css  js  c++  java
  • 简易遍历 寻找0/1串中 连续10个1首次出现位置(递归)

    //A1.java

    public class A1 {

        
    private final static int N = 10;

        
    public static void main(String[] args) {
            String str 
    = "0010000110111101011010101000101001110111000110010001111010111100011000011111111110100100001111110001101011010001000101011100011100111000110010010111100101101011100010110100111010000001000101110101111000001111100110101010010101011011010110011010101000111011001001110111000011001110111001100010001001010100111001111111110100000110001100010101101000011111011000011111111101100000010000000111111000000101111011110101101110101101100100001011110110010110111001110110001011110000111100000000010011101100101010101100101110000011100100010000101100101001001001000101001100010100011000110001011010101010000101000111000101011100111011101101110010100110001011011100110001110010010010101101111001101101100100100011001110111111110100001001001110101101100111101101000110000101000111000001011111010000110000011110001111100100010011100001010111011110011011101010101011011101100011110001101011110100011100011100110111110010101110011101000000011100111000111001001101000011100011001110100110110100111100111011000000011000";
            System.out.println(
    "index:" + exec(str, 00));
        }

        
    public static int exec(String str, int i, int count) {
            
    if (count == N) {
                System.out.println(
    "i:" + i);
                
    return i - 10;
            }
            
    if (i == str.length()) {
                
    return -1;
            }
            
    if (str.charAt(i) == '0') {
                
    return exec(str, i + 10);
            } 
    else {
                
    return exec(str, i + 1, count + 1);
            }
        }
    }

  • 相关阅读:
    BZOJ_4320_ShangHai2006 Homework_分块
    BZOJ_3362_[Usaco2004 Feb]Navigation Nightmare 导航噩梦_并查集
    BZOJ_2788_[Poi2012]Festival_差分约束+tarjan+floyed
    BZOJ_2795_[Poi2012]A Horrible Poem_hash+暴力
    BZOJ_1598_[Usaco2008 Mar]牛跑步_A*
    [转载]java匿名对象
    [转载]static in Java
    Bat批处理文件入门
    在set中放入自定义类型
    [转载]C++STL概述
  • 原文地址:https://www.cnblogs.com/huidaoli/p/3202670.html
Copyright © 2011-2022 走看看