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);
            }
        }
    }

  • 相关阅读:
    linux下用shell删除三天前或者三天内的文件
    linux在shell中获取时间
    mongodb_修改器($inc/$set/$unset/$push/$pop/upsert......)
    java List<Map> 排序问题
    linux crontab定时执行shell脚本
    MongoDB 基础命令——数据库表的增删改查——遍历操作表中的记录
    Windows7下安装MongoDB
    JavaWeb学习总结(十二)——Session
    javaweb学习总结(十一)——使用Cookie进行会话管理
    iOS10 SiriKit QQ适配详解
  • 原文地址:https://www.cnblogs.com/huidaoli/p/3202670.html
Copyright © 2011-2022 走看看