#include<stdio.h>
#include<sstream>
#include <map>
#include <iostream>
#include <math.h>
using namespace std;
char * P ;
void GetNearest(int N)
{
P=new char[N+1];
for(int i=0;i<N;i++)
{
P[i]='0';
}
P[N]=0;
cout<<P<<endl;
for(int i=0;i<N;i++)
{
P[N-i-1]='1';
cout<<P<<endl;
for(int j=0;j<(int)pow(2.0,i)-1;j++)
{
P[N-j%i-1]=P[N-j%i-1]=='0'?'1':'0';
cout<<P<<endl;
}
}
}
void main()
{
GetNearest(4);
}
#include<sstream>
#include <map>
#include <iostream>
#include <math.h>
using namespace std;
char * P ;
void GetNearest(int N)
{
P=new char[N+1];
for(int i=0;i<N;i++)
{
P[i]='0';
}
P[N]=0;
cout<<P<<endl;
for(int i=0;i<N;i++)
{
P[N-i-1]='1';
cout<<P<<endl;
for(int j=0;j<(int)pow(2.0,i)-1;j++)
{
P[N-j%i-1]=P[N-j%i-1]=='0'?'1':'0';
cout<<P<<endl;
}
}
}
void main()
{
GetNearest(4);
}
本文展示了一个使用C++进行位操作的示例程序,该程序通过改变字符串中的特定字符来生成不同的二进制组合。它使用了基本的C++语法和标准库,包括字符串操作和数学函数。
1375

被折叠的 条评论
为什么被折叠?



