c# 编程题,大佬直接留下代码,输入字符串(可以是字母也可以是数字)输出所有子字符串不能用递归等

Write a program that reads a string from standard input. The string will appear on a single line, and will contain no whitespace characters. You may assume that all characters in the string are unique.

Your program should print out all non-empty subsequences of characters that can be formed from the characters in the input string. Write each subsequence on a separate line. The characters in each subsequence must appear in the same order as in the original string. You may write the subsequences in any order.

Important: All of your code must appear in Main(); you may not write any other functions/methods (nested or otherwise). After all, we haven't learned about writing methods in C# yet. :) And so you may not use recursion to solve this problem as we did in Programming 1.

Sample input:

jump

Possible output:

j
u
ju
m
jm
um
jum
p
jp
up
jup
mp
jmp
ump
jump

Hint: If N is the length of the input string, there are 2^N possible subsequences (including the empty sequence). That's because each of the N input letters either is or is not in the output, so there are 2 possibilities for that letter.

There also happen to be 2^N numbers that can be written using N digits in binary representation (i.e. base 2). If you can generate those binary numbers, you can use each one to generate an output string (excepting the empty string).

using System;
namespace HelloWorldApplication
{
    class HelloWorld
    {
        static void Main(string[] args)
        {
            /* 我的第一个 C# 程序*/
			String line;
            //line="jump";
			line = Console.ReadLine();
			int n = line.Length;
			long  maxn = 1 << n;
			for(int i = 0; i < maxn; i++){
				for(int j = 0; j < n; j++){
					long mask = 1 << j;
					long masked = i & mask;
					if(masked!=0){
						Console.Write(line[j]);
					}
				}
				Console.Write("\n");
			}
        }
    }
}

你好,我是问答小助手,非常抱歉,本次您提出的有问必答问题,超出我们目前的服务范围,暂时无法为您解答。


问答VIP目前服务范围为 :Python、Java、MySQL、Redis、网络、Linux、大数据、云计算、云原生、中间件、MongoDB、HBase、Zookeeper、Kafka等领域专业问题解答,为您提供解决问题的思路和指导。不包含源码代写、项目文档代写、论文代写、安装包资源发送或安装指导等服务。

本次提问扣除的有问必答次数,已经为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。

 存在一些跳顺序的,比如jump--jmp ,up之类的

题目输出:

j

u

ju

m

jm

um

jum

p

jp

up

jup

mp

jmp

ump

jump