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++[
^]