zoukankan      html  css  js  c++  java
  • 字符串的全部子序列(递归)

    打印一个字符串的全部子序列, 包括空字符串

    输入:

    abc

    输出:
        // 第一个是空串
    c
    b
    bc
    a
    ac
    ab
    abc

    import java.io.BufferedInputStream;
    import java.util.Scanner;
    
    public class test {
    
        public static void printAllSub(char[] str, int i, String res) {
            if (i == str.length) {
                System.out.println(res);
                return ;
            } else {
                printAllSub(str, i + 1, res); // 不要下标为i+1的字符
                printAllSub(str, i + 1, res+str[i]); // 要第i+1个字符
            }
        }
        
        public static void main(String[] args) {
            Scanner cin = new Scanner(new BufferedInputStream(System.in));
            String str = cin.next();
            printAllSub(str.toCharArray(), 0, "");
            cin.close();
        }
    }
    ========================================Talk is cheap, show me the code=======================================
    CSDN博客地址:https://blog.csdn.net/qq_34115899
  • 相关阅读:
    python计算均值方差
    Linux shell一行流编程实践
    where are you from
    dinner vs supper
    Python格式化输出
    吐槽win8
    HTML学习(六)图像
    HTML学习(五)链接
    HTML学习(四)样式
    URL与String转换
  • 原文地址:https://www.cnblogs.com/lcy0515/p/9179780.html
Copyright © 2011-2022 走看看