Home > Back-end >  Exhaustive specific bit binary number
Exhaustive specific bit binary number

Time:03-26

O bosses!

Enter a raw binary string (char types, not string), poor examples of non zero produces all possible

example:

Raw data:
000 11 1

Results:
000 0
000 1
000 0 01 0
000 0 01 1
000 10 0
000 10 1
000 11 0
000 11 1

CodePudding user response:

Using hexadecimal conversion can be realized, the first turn in binary decimal, again from the decimal 0 to binary, decimal value by the binary switch.

CodePudding user response:

 int main () {
Unsigned char arr [256] {0}.
Unsigned char x=0 xd;
for (int i=0; I & lt; 255; I++) {
Unsigned int b=I & amp; x;
Arr [b]=1;
}
for (int i=0; I & lt; 256; I++) {
If (arr [I])
Printf (" % 2 x \ r \ n ", I);
}
return 0;
}

CodePudding user response:

Write two functions: two to hexadecimal decimal, decimal turn two to hex, then call these two functions can be realized.

CodePudding user response:

The original binary string without length? !
1, 10000 to destroy earth day can run out the result?

CodePudding user response:

If the input digits must be, and the relatively small, can take advantage of the method on the second floor of the
If the input digits can be quite large, the 0 out first, and then only 1, look at a few, then add up from 0 to go, is to produce the red on the number of these, you then can be put back to the previous 0, this should be the safest, pay attention to the insertion technique

CodePudding user response:

I think you all understand the wrong... The title of the original poster is string operation problems
 
# include & lt; iostream>
# include & lt; Set>
using namespace std;
Set Sset;
Void traversestr (string STR)
{
Sset. Insert (STR);
for (int i=0; I & lt; 8; + + I)
{
If (STR [I]=='1') {
Char c=STR [I];
STR [I]='0';
Traversestr (STR);
STR [I]=c;
}
}
}

Bool checkStr (string STR)
{
If (STR) length ()! {
=8)Cout & lt; <"Input length not match" & lt; return false;
}
for (int i=0; I & lt; 8; + + I) {
If (STR [I]!='0' & amp; & STR [I]!='1') {
Cout & lt; <"Input data not available" & lt; return false;
}
}
return true;
}

Int main () {
String STR.
Do {
Cin. The clear ();
Cin & gt;> STR;
}while(! CheckStr (STR));
Traversestr (STR);
Set : : iterator it=sset. The begin ();
For (; it !=sset. End (); + + it)
{
Cout & lt; <* it & lt;
};
return 0;
}

CodePudding user response:

quoted zhao 4, 4/f, the teacher's reply:
raw binary string without length? !
1, 10000 to destroy earth day can run out the result?


Example is very simple, normally 144 - bit binary number, probably there are 20 non zero, intermediate variable is stored in the plastic array must not

CodePudding user response:

refer to 6th floor NorZ response:
I think you all understand the wrong... The title of the original poster is string operation problems
 
# include & lt; iostream>
# include & lt; Set>
using namespace std;
Set Sset;
Void traversestr (string STR)
{
Sset. Insert (STR);
for (int i=0; I & lt; 8; + + I)
{
If (STR [I]=='1') {
Char c=STR [I];
STR [I]='0';
Traversestr (STR);
STR [I]=c;
}
}
}

Bool checkStr (string STR)
{
If (STR) length ()! {
=8)Cout & lt; <"Input length not match" & lt; return false;
}
for (int i=0; I & lt; 8; + + I) {
If (STR [I]!='0' & amp; & STR [I]!='1') {
Cout & lt; <"Input data not available" & lt; return false;
}
}
return true;
}

Int main () {
String STR.
Do {
Cin. The clear ();
Cin & gt;> STR;
}while(! CheckStr (STR));
Traversestr (STR);
Set : : iterator it=sset. The begin ();
For (; it !=sset. End (); + + it)
{
Cout & lt; <* it & lt;
};
return 0;
}



This program I don't know what is your input, I give examples of inputs such as 101110000010, the output will be 2 ^ 5 kinds of non zero permutation and combination of binary string, and not the string type is char array

CodePudding user response:

reference 5 floor flying_music reply:
if the input digits must be, and the relatively small, can take advantage of the method on the second floor of the
If the input digits can be quite large, the 0 out first, and then only 1, look at a few, then add up from 0 to go, is to produce the red on the number of these, you then can be put back to the previous 0, this should be the safest, pay attention to the insertion technique can


Thinking I probably understand, but the program can't write, eliminate exhaustion directly after 0 2 ^ n combinations (n is the number zero), then add 0 back to its original position,

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related