一种删除字符串中大写字母的所有可能方法的算法 [英] An algorithm of all possible ways to remove capital letters in a string
问题描述
您好。
我正在开发一个项目,其中部分内容我需要一个函数,它返回所有可能的方法来删除字符串的大写字母作为List或数组。 />
例如我的字符串是:aAbBcCdD
算法或函数必须返回像这样的List或数组:
aAbBcCdD
abBcCdD
aAbcCdD
aAbBcdD
aAbBcCd
abcCdD
abBcdD
abBcCd
aAbcdD
aAbcCd
aAbBcd
abcdD
abcCd
abBcd
aAbcd
abcd
我搜索了很多关于它的信息并且有人说使用递归函数,它将所有可能性的笛卡尔乘积用于第一个字母和函数应用于字符串的其余部分。(如果第一个字母是大写字母,则有两种可能性。如果第一个字母是小写字母,则只有一种可能性。)
我对递归函数和笛卡尔积有一些了解,但我不知道怎么能让它变得可能!
是否有人可以提供帮助我?
谢谢。
我的尝试:
几乎没有:(
这个问题有很多算法。
你可以考虑让一个资本或删除它是二元的东西。
4个资本意味着2 ^ 4种可能性。从0到15(2 ^ 4-1)的计数将匹配所有组合。
0 => 0000B => aAbBcCdD
1 => 0001B => aAbBcCd
2 => 0010B => aAbBcdD
3 => 0011B => aAbBcd
4 => 0100B => aAbcCdD
5 => 0101B => aAbcCd
6 => 0110B => aAbcdD
7 => 0111b => aAbcd
8 => 1000B => abBcCdD
9 => 1001B => abBcCd
10 => 1010B => abBcdD
11 => 1011B => abBcd
12 => 1100B => abcCdD
13 => 1101B => abcCd
14 => 1110B => abcdD
15 => 1111B => abcd
[更新]
为了检查给定值的每个位,你必须使用按位逻辑运算符。
(值& 8)告诉您是否必须删除A。
(值& 1)告诉您是否必须删除D。
3.8—按位运算符& laquo;学习C ++ [ ^ ]
Hello.
I'm working on a project which in part of it I need a function which returns all possible ways to remove Capital letters of a string as a List or an Array.
For Example my string is : aAbBcCdD
The algorithm or function must return a List or an Array like this :
aAbBcCdD
abBcCdD
aAbcCdD
aAbBcdD
aAbBcCd
abcCdD
abBcdD
abBcCd
aAbcdD
aAbcCd
aAbBcd
abcdD
abcCd
abBcd
aAbcd
abcd
I searched so much about it and someone said "use a recursive function that takes the Cartesian product of all possibilities for the first letter and the function applied to the rest of the string. (If the first letter is a capital, there are two possibilities. If the first letter is lowercase, there is only one possibility.)"
I know a little bit about Recursive functions and Cartesian product but I've no idea how can I make it possible !
is there anyone who can help me ?
thanks.
What I have tried:
A l m o s t n o t h i n g :(
There is many algorithms for this problem.
you can consider that let a capital or remove it is a binary thing.
4 capitals means 2^4 possibilities. Counting from 0 to 15 (2^4-1) will match all combinations.
0=> 0000b=> aAbBcCdD 1=> 0001b=> aAbBcCd 2=> 0010b=> aAbBcdD 3=> 0011b=> aAbBcd 4=> 0100b=> aAbcCdD 5=> 0101b=> aAbcCd 6=> 0110b=> aAbcdD 7=> 0111b=> aAbcd 8=> 1000b=> abBcCdD 9=> 1001b=> abBcCd 10=> 1010b=> abBcdD 11=> 1011b=> abBcd 12=> 1100b=> abcCdD 13=> 1101b=> abcCd 14=> 1110b=> abcdD 15=> 1111b=> abcd
[Update]
In order to check each bit for a given value, you have to use bitwise logic operators.
(value & 8) tells you if you have to remove "A" or not.
(value & 1) tells you if you have to remove "D" or not.
3.8 — Bitwise operators « Learn C++[^]
这篇关于一种删除字符串中大写字母的所有可能方法的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!