Bitmasking and searching consecutive 1's
up vote
4
down vote
favorite
I have written code to count the continuous ones in an array or you can use binary string for convenience. Any solution using the binary string is acceptable.
My Solution is:
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
int main()
{
int n,q,k,count;
string str;
cin>>n>>q>>k;
bitset<MAX>s,c;
//inserting bits in array
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
s[i]=temp;
}
cin>>str;
for(int i=0;i<q;i++)
{
//making duplicate bitset
c=s;
if(str[i]=='?')
{
count=0;
while(c!=0)
{
//using bitmask to count maximum no of continuous 1's-O(1's bit)
c=(c&(c<<1));
count++;
}
if(count>k)
cout<<k<<"n";
else
cout<<count<<"n";
}
else
{
//shifting each bit to right and updating first bit with previous last
// bit
bool lb=s[n-1];
s=s>>1;
s[n-1]=lb;
}
}
}
c++ programming-challenge bitset
New contributor
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
4
down vote
favorite
I have written code to count the continuous ones in an array or you can use binary string for convenience. Any solution using the binary string is acceptable.
My Solution is:
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
int main()
{
int n,q,k,count;
string str;
cin>>n>>q>>k;
bitset<MAX>s,c;
//inserting bits in array
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
s[i]=temp;
}
cin>>str;
for(int i=0;i<q;i++)
{
//making duplicate bitset
c=s;
if(str[i]=='?')
{
count=0;
while(c!=0)
{
//using bitmask to count maximum no of continuous 1's-O(1's bit)
c=(c&(c<<1));
count++;
}
if(count>k)
cout<<k<<"n";
else
cout<<count<<"n";
}
else
{
//shifting each bit to right and updating first bit with previous last
// bit
bool lb=s[n-1];
s=s>>1;
s[n-1]=lb;
}
}
}
c++ programming-challenge bitset
New contributor
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
Try to give an example with possible value and invalid inputs and expected outputs. it will help people to figure out the way and the purpose of your programme.
– Calak
Nov 6 at 14:52
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have written code to count the continuous ones in an array or you can use binary string for convenience. Any solution using the binary string is acceptable.
My Solution is:
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
int main()
{
int n,q,k,count;
string str;
cin>>n>>q>>k;
bitset<MAX>s,c;
//inserting bits in array
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
s[i]=temp;
}
cin>>str;
for(int i=0;i<q;i++)
{
//making duplicate bitset
c=s;
if(str[i]=='?')
{
count=0;
while(c!=0)
{
//using bitmask to count maximum no of continuous 1's-O(1's bit)
c=(c&(c<<1));
count++;
}
if(count>k)
cout<<k<<"n";
else
cout<<count<<"n";
}
else
{
//shifting each bit to right and updating first bit with previous last
// bit
bool lb=s[n-1];
s=s>>1;
s[n-1]=lb;
}
}
}
c++ programming-challenge bitset
New contributor
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have written code to count the continuous ones in an array or you can use binary string for convenience. Any solution using the binary string is acceptable.
My Solution is:
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
int main()
{
int n,q,k,count;
string str;
cin>>n>>q>>k;
bitset<MAX>s,c;
//inserting bits in array
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
s[i]=temp;
}
cin>>str;
for(int i=0;i<q;i++)
{
//making duplicate bitset
c=s;
if(str[i]=='?')
{
count=0;
while(c!=0)
{
//using bitmask to count maximum no of continuous 1's-O(1's bit)
c=(c&(c<<1));
count++;
}
if(count>k)
cout<<k<<"n";
else
cout<<count<<"n";
}
else
{
//shifting each bit to right and updating first bit with previous last
// bit
bool lb=s[n-1];
s=s>>1;
s[n-1]=lb;
}
}
}
c++ programming-challenge bitset
c++ programming-challenge bitset
New contributor
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Nov 6 at 16:26
bruglesco
1,1092520
1,1092520
New contributor
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 6 at 13:23
Raja Babu
274
274
New contributor
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Raja Babu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4
Try to give an example with possible value and invalid inputs and expected outputs. it will help people to figure out the way and the purpose of your programme.
– Calak
Nov 6 at 14:52
add a comment |
4
Try to give an example with possible value and invalid inputs and expected outputs. it will help people to figure out the way and the purpose of your programme.
– Calak
Nov 6 at 14:52
4
4
Try to give an example with possible value and invalid inputs and expected outputs. it will help people to figure out the way and the purpose of your programme.
– Calak
Nov 6 at 14:52
Try to give an example with possible value and invalid inputs and expected outputs. it will help people to figure out the way and the purpose of your programme.
– Calak
Nov 6 at 14:52
add a comment |
3 Answers
3
active
oldest
votes
up vote
10
down vote
<bits/stdc++.h> (like everything in your compiler's bits/ subtree) is not a standard header and therefore not portable. Even if you're willing to sacrifice portability, it's a poor choice, as it will slow compilation down compared to simply including what you use.
using namespace std; is poor practice. It makes your code less clear, and it may even silently change its meaning.
Don't use the preprocessor to name constants. Use a properly scoped, strongly typed C++ constant:
constexpr std::size_t max = 100000;
When using input streams, always check that operations succeed before using their results.
Variable names should be more descriptive. I have no idea what n, q, and k are supposed to be storing. In fact, these names are so useless that I gave up reading at this point - it's not at all clear what this is supposed to be doing.
i don't know how to do it.
– Raja Babu
Nov 6 at 16:26
add a comment |
up vote
5
down vote
- When you post code to be reviewed:
- If your code ask for input, provide a set of valid an invalids inputs
- If your code output a result, express expected.
- Since you present your code, it may be interesting to embrace a coding standard. You do not pay taxes on written characters. Do not be afraid to use spaces to improve readability.
Don't include<bits/stdc++.h>`:
- It's not a standard header. If you try to compile your code with MSVC, he will complain that he can't find him.
- Even if you use only GCC, it would include so much unnecessary things that your compilation time will increase considerably.
- Instead, explicitly includes all header needed.
Don't useusing namespace std;:
- Although it's "safe" to use it in some place (e.g. implementation files), as long as you are not familiar with the features of c ++, try to avoid it.
- It led to a world of name collisions. (best case)
- It's source of silent errors and weird bugs. (worst case)
- If typing
std::is so tedious for you, try to import only truncated namespaces. ( egusing namespace std::string;). - If importing nested namespaces still too awful for you, try to do it inside a restricted scope (eg a functions) and not in global scope.
Don't use preprocessors to defines constants values, instead use const variable.
Chose good name for variables. what'sn,qorkmean? They are int, but? And forsorc, we know they arebitset<MAX>, but nothing more.
Write expressive code, in which your intentions are clearly stated.
Don't declare more than one variable at a time. It led to error, mainly working with pointer or initialization.
Always initialize a variable when you declare it.- Extract the code into reusable functions , short as possible, and that operate a reduced and well defined number of statements. (see Single responsibility principle). (eg, a function that asks the user to enter an input, reads them and returns them)
- If you ask user to input some values, really ask (tell to user what he have to write)
- When you read values from user input, consider it ill-formed, so check for validity. Here you don't check after getting the int's. Futhermore, you don't check the length of the string and but access it by indexes, etc.
- The
mainfunction should return an integer.
add a comment |
up vote
3
down vote
Don't declare multiple variables on a single line. it is error prone and more difficult to read.
int n,q,k,count;
should be:
int n;
int q;
int k;
int count;
Not sure what I mean by error prone?
int* n,q,k,count;
How many pointers do you have? one. only n would be a pointer in this declaration.
Let your operators breathe. The lack of whitespace makes your code harder to read.
for(int i = 0; i < n; i++)
{
int temp;
cin >> temp;
s[i] = temp;
}
this is a little easier to distinguish.
Prefer prefix to postfix
Use more consistent indentation. I had to read the code three times just to realize that the scope braces didn't line up with each other. I almost flagged to close because
for ()
{
}
else
{}
would be broken, and that's how your braces line up horizontally.
FWIW, if*for pointer types are written before the variable name, then the declaration becomesint *n, q, k, count, which is less ambiguous.
– Quelklef
2 days ago
2
@Quelklef yes but that is also often taught as a poor practice in C++. Regardless single line multi-variable declarations are harder to read.
– bruglesco
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
<bits/stdc++.h> (like everything in your compiler's bits/ subtree) is not a standard header and therefore not portable. Even if you're willing to sacrifice portability, it's a poor choice, as it will slow compilation down compared to simply including what you use.
using namespace std; is poor practice. It makes your code less clear, and it may even silently change its meaning.
Don't use the preprocessor to name constants. Use a properly scoped, strongly typed C++ constant:
constexpr std::size_t max = 100000;
When using input streams, always check that operations succeed before using their results.
Variable names should be more descriptive. I have no idea what n, q, and k are supposed to be storing. In fact, these names are so useless that I gave up reading at this point - it's not at all clear what this is supposed to be doing.
i don't know how to do it.
– Raja Babu
Nov 6 at 16:26
add a comment |
up vote
10
down vote
<bits/stdc++.h> (like everything in your compiler's bits/ subtree) is not a standard header and therefore not portable. Even if you're willing to sacrifice portability, it's a poor choice, as it will slow compilation down compared to simply including what you use.
using namespace std; is poor practice. It makes your code less clear, and it may even silently change its meaning.
Don't use the preprocessor to name constants. Use a properly scoped, strongly typed C++ constant:
constexpr std::size_t max = 100000;
When using input streams, always check that operations succeed before using their results.
Variable names should be more descriptive. I have no idea what n, q, and k are supposed to be storing. In fact, these names are so useless that I gave up reading at this point - it's not at all clear what this is supposed to be doing.
i don't know how to do it.
– Raja Babu
Nov 6 at 16:26
add a comment |
up vote
10
down vote
up vote
10
down vote
<bits/stdc++.h> (like everything in your compiler's bits/ subtree) is not a standard header and therefore not portable. Even if you're willing to sacrifice portability, it's a poor choice, as it will slow compilation down compared to simply including what you use.
using namespace std; is poor practice. It makes your code less clear, and it may even silently change its meaning.
Don't use the preprocessor to name constants. Use a properly scoped, strongly typed C++ constant:
constexpr std::size_t max = 100000;
When using input streams, always check that operations succeed before using their results.
Variable names should be more descriptive. I have no idea what n, q, and k are supposed to be storing. In fact, these names are so useless that I gave up reading at this point - it's not at all clear what this is supposed to be doing.
<bits/stdc++.h> (like everything in your compiler's bits/ subtree) is not a standard header and therefore not portable. Even if you're willing to sacrifice portability, it's a poor choice, as it will slow compilation down compared to simply including what you use.
using namespace std; is poor practice. It makes your code less clear, and it may even silently change its meaning.
Don't use the preprocessor to name constants. Use a properly scoped, strongly typed C++ constant:
constexpr std::size_t max = 100000;
When using input streams, always check that operations succeed before using their results.
Variable names should be more descriptive. I have no idea what n, q, and k are supposed to be storing. In fact, these names are so useless that I gave up reading at this point - it's not at all clear what this is supposed to be doing.
answered Nov 6 at 14:28
Toby Speight
21.6k536106
21.6k536106
i don't know how to do it.
– Raja Babu
Nov 6 at 16:26
add a comment |
i don't know how to do it.
– Raja Babu
Nov 6 at 16:26
i don't know how to do it.
– Raja Babu
Nov 6 at 16:26
i don't know how to do it.
– Raja Babu
Nov 6 at 16:26
add a comment |
up vote
5
down vote
- When you post code to be reviewed:
- If your code ask for input, provide a set of valid an invalids inputs
- If your code output a result, express expected.
- Since you present your code, it may be interesting to embrace a coding standard. You do not pay taxes on written characters. Do not be afraid to use spaces to improve readability.
Don't include<bits/stdc++.h>`:
- It's not a standard header. If you try to compile your code with MSVC, he will complain that he can't find him.
- Even if you use only GCC, it would include so much unnecessary things that your compilation time will increase considerably.
- Instead, explicitly includes all header needed.
Don't useusing namespace std;:
- Although it's "safe" to use it in some place (e.g. implementation files), as long as you are not familiar with the features of c ++, try to avoid it.
- It led to a world of name collisions. (best case)
- It's source of silent errors and weird bugs. (worst case)
- If typing
std::is so tedious for you, try to import only truncated namespaces. ( egusing namespace std::string;). - If importing nested namespaces still too awful for you, try to do it inside a restricted scope (eg a functions) and not in global scope.
Don't use preprocessors to defines constants values, instead use const variable.
Chose good name for variables. what'sn,qorkmean? They are int, but? And forsorc, we know they arebitset<MAX>, but nothing more.
Write expressive code, in which your intentions are clearly stated.
Don't declare more than one variable at a time. It led to error, mainly working with pointer or initialization.
Always initialize a variable when you declare it.- Extract the code into reusable functions , short as possible, and that operate a reduced and well defined number of statements. (see Single responsibility principle). (eg, a function that asks the user to enter an input, reads them and returns them)
- If you ask user to input some values, really ask (tell to user what he have to write)
- When you read values from user input, consider it ill-formed, so check for validity. Here you don't check after getting the int's. Futhermore, you don't check the length of the string and but access it by indexes, etc.
- The
mainfunction should return an integer.
add a comment |
up vote
5
down vote
- When you post code to be reviewed:
- If your code ask for input, provide a set of valid an invalids inputs
- If your code output a result, express expected.
- Since you present your code, it may be interesting to embrace a coding standard. You do not pay taxes on written characters. Do not be afraid to use spaces to improve readability.
Don't include<bits/stdc++.h>`:
- It's not a standard header. If you try to compile your code with MSVC, he will complain that he can't find him.
- Even if you use only GCC, it would include so much unnecessary things that your compilation time will increase considerably.
- Instead, explicitly includes all header needed.
Don't useusing namespace std;:
- Although it's "safe" to use it in some place (e.g. implementation files), as long as you are not familiar with the features of c ++, try to avoid it.
- It led to a world of name collisions. (best case)
- It's source of silent errors and weird bugs. (worst case)
- If typing
std::is so tedious for you, try to import only truncated namespaces. ( egusing namespace std::string;). - If importing nested namespaces still too awful for you, try to do it inside a restricted scope (eg a functions) and not in global scope.
Don't use preprocessors to defines constants values, instead use const variable.
Chose good name for variables. what'sn,qorkmean? They are int, but? And forsorc, we know they arebitset<MAX>, but nothing more.
Write expressive code, in which your intentions are clearly stated.
Don't declare more than one variable at a time. It led to error, mainly working with pointer or initialization.
Always initialize a variable when you declare it.- Extract the code into reusable functions , short as possible, and that operate a reduced and well defined number of statements. (see Single responsibility principle). (eg, a function that asks the user to enter an input, reads them and returns them)
- If you ask user to input some values, really ask (tell to user what he have to write)
- When you read values from user input, consider it ill-formed, so check for validity. Here you don't check after getting the int's. Futhermore, you don't check the length of the string and but access it by indexes, etc.
- The
mainfunction should return an integer.
add a comment |
up vote
5
down vote
up vote
5
down vote
- When you post code to be reviewed:
- If your code ask for input, provide a set of valid an invalids inputs
- If your code output a result, express expected.
- Since you present your code, it may be interesting to embrace a coding standard. You do not pay taxes on written characters. Do not be afraid to use spaces to improve readability.
Don't include<bits/stdc++.h>`:
- It's not a standard header. If you try to compile your code with MSVC, he will complain that he can't find him.
- Even if you use only GCC, it would include so much unnecessary things that your compilation time will increase considerably.
- Instead, explicitly includes all header needed.
Don't useusing namespace std;:
- Although it's "safe" to use it in some place (e.g. implementation files), as long as you are not familiar with the features of c ++, try to avoid it.
- It led to a world of name collisions. (best case)
- It's source of silent errors and weird bugs. (worst case)
- If typing
std::is so tedious for you, try to import only truncated namespaces. ( egusing namespace std::string;). - If importing nested namespaces still too awful for you, try to do it inside a restricted scope (eg a functions) and not in global scope.
Don't use preprocessors to defines constants values, instead use const variable.
Chose good name for variables. what'sn,qorkmean? They are int, but? And forsorc, we know they arebitset<MAX>, but nothing more.
Write expressive code, in which your intentions are clearly stated.
Don't declare more than one variable at a time. It led to error, mainly working with pointer or initialization.
Always initialize a variable when you declare it.- Extract the code into reusable functions , short as possible, and that operate a reduced and well defined number of statements. (see Single responsibility principle). (eg, a function that asks the user to enter an input, reads them and returns them)
- If you ask user to input some values, really ask (tell to user what he have to write)
- When you read values from user input, consider it ill-formed, so check for validity. Here you don't check after getting the int's. Futhermore, you don't check the length of the string and but access it by indexes, etc.
- The
mainfunction should return an integer.
- When you post code to be reviewed:
- If your code ask for input, provide a set of valid an invalids inputs
- If your code output a result, express expected.
- Since you present your code, it may be interesting to embrace a coding standard. You do not pay taxes on written characters. Do not be afraid to use spaces to improve readability.
Don't include<bits/stdc++.h>`:
- It's not a standard header. If you try to compile your code with MSVC, he will complain that he can't find him.
- Even if you use only GCC, it would include so much unnecessary things that your compilation time will increase considerably.
- Instead, explicitly includes all header needed.
Don't useusing namespace std;:
- Although it's "safe" to use it in some place (e.g. implementation files), as long as you are not familiar with the features of c ++, try to avoid it.
- It led to a world of name collisions. (best case)
- It's source of silent errors and weird bugs. (worst case)
- If typing
std::is so tedious for you, try to import only truncated namespaces. ( egusing namespace std::string;). - If importing nested namespaces still too awful for you, try to do it inside a restricted scope (eg a functions) and not in global scope.
Don't use preprocessors to defines constants values, instead use const variable.
Chose good name for variables. what'sn,qorkmean? They are int, but? And forsorc, we know they arebitset<MAX>, but nothing more.
Write expressive code, in which your intentions are clearly stated.
Don't declare more than one variable at a time. It led to error, mainly working with pointer or initialization.
Always initialize a variable when you declare it.- Extract the code into reusable functions , short as possible, and that operate a reduced and well defined number of statements. (see Single responsibility principle). (eg, a function that asks the user to enter an input, reads them and returns them)
- If you ask user to input some values, really ask (tell to user what he have to write)
- When you read values from user input, consider it ill-formed, so check for validity. Here you don't check after getting the int's. Futhermore, you don't check the length of the string and but access it by indexes, etc.
- The
mainfunction should return an integer.
edited 2 days ago
answered Nov 6 at 20:06
Calak
1,15312
1,15312
add a comment |
add a comment |
up vote
3
down vote
Don't declare multiple variables on a single line. it is error prone and more difficult to read.
int n,q,k,count;
should be:
int n;
int q;
int k;
int count;
Not sure what I mean by error prone?
int* n,q,k,count;
How many pointers do you have? one. only n would be a pointer in this declaration.
Let your operators breathe. The lack of whitespace makes your code harder to read.
for(int i = 0; i < n; i++)
{
int temp;
cin >> temp;
s[i] = temp;
}
this is a little easier to distinguish.
Prefer prefix to postfix
Use more consistent indentation. I had to read the code three times just to realize that the scope braces didn't line up with each other. I almost flagged to close because
for ()
{
}
else
{}
would be broken, and that's how your braces line up horizontally.
FWIW, if*for pointer types are written before the variable name, then the declaration becomesint *n, q, k, count, which is less ambiguous.
– Quelklef
2 days ago
2
@Quelklef yes but that is also often taught as a poor practice in C++. Regardless single line multi-variable declarations are harder to read.
– bruglesco
2 days ago
add a comment |
up vote
3
down vote
Don't declare multiple variables on a single line. it is error prone and more difficult to read.
int n,q,k,count;
should be:
int n;
int q;
int k;
int count;
Not sure what I mean by error prone?
int* n,q,k,count;
How many pointers do you have? one. only n would be a pointer in this declaration.
Let your operators breathe. The lack of whitespace makes your code harder to read.
for(int i = 0; i < n; i++)
{
int temp;
cin >> temp;
s[i] = temp;
}
this is a little easier to distinguish.
Prefer prefix to postfix
Use more consistent indentation. I had to read the code three times just to realize that the scope braces didn't line up with each other. I almost flagged to close because
for ()
{
}
else
{}
would be broken, and that's how your braces line up horizontally.
FWIW, if*for pointer types are written before the variable name, then the declaration becomesint *n, q, k, count, which is less ambiguous.
– Quelklef
2 days ago
2
@Quelklef yes but that is also often taught as a poor practice in C++. Regardless single line multi-variable declarations are harder to read.
– bruglesco
2 days ago
add a comment |
up vote
3
down vote
up vote
3
down vote
Don't declare multiple variables on a single line. it is error prone and more difficult to read.
int n,q,k,count;
should be:
int n;
int q;
int k;
int count;
Not sure what I mean by error prone?
int* n,q,k,count;
How many pointers do you have? one. only n would be a pointer in this declaration.
Let your operators breathe. The lack of whitespace makes your code harder to read.
for(int i = 0; i < n; i++)
{
int temp;
cin >> temp;
s[i] = temp;
}
this is a little easier to distinguish.
Prefer prefix to postfix
Use more consistent indentation. I had to read the code three times just to realize that the scope braces didn't line up with each other. I almost flagged to close because
for ()
{
}
else
{}
would be broken, and that's how your braces line up horizontally.
Don't declare multiple variables on a single line. it is error prone and more difficult to read.
int n,q,k,count;
should be:
int n;
int q;
int k;
int count;
Not sure what I mean by error prone?
int* n,q,k,count;
How many pointers do you have? one. only n would be a pointer in this declaration.
Let your operators breathe. The lack of whitespace makes your code harder to read.
for(int i = 0; i < n; i++)
{
int temp;
cin >> temp;
s[i] = temp;
}
this is a little easier to distinguish.
Prefer prefix to postfix
Use more consistent indentation. I had to read the code three times just to realize that the scope braces didn't line up with each other. I almost flagged to close because
for ()
{
}
else
{}
would be broken, and that's how your braces line up horizontally.
answered Nov 6 at 15:43
bruglesco
1,1092520
1,1092520
FWIW, if*for pointer types are written before the variable name, then the declaration becomesint *n, q, k, count, which is less ambiguous.
– Quelklef
2 days ago
2
@Quelklef yes but that is also often taught as a poor practice in C++. Regardless single line multi-variable declarations are harder to read.
– bruglesco
2 days ago
add a comment |
FWIW, if*for pointer types are written before the variable name, then the declaration becomesint *n, q, k, count, which is less ambiguous.
– Quelklef
2 days ago
2
@Quelklef yes but that is also often taught as a poor practice in C++. Regardless single line multi-variable declarations are harder to read.
– bruglesco
2 days ago
FWIW, if
* for pointer types are written before the variable name, then the declaration becomes int *n, q, k, count, which is less ambiguous.– Quelklef
2 days ago
FWIW, if
* for pointer types are written before the variable name, then the declaration becomes int *n, q, k, count, which is less ambiguous.– Quelklef
2 days ago
2
2
@Quelklef yes but that is also often taught as a poor practice in C++. Regardless single line multi-variable declarations are harder to read.
– bruglesco
2 days ago
@Quelklef yes but that is also often taught as a poor practice in C++. Regardless single line multi-variable declarations are harder to read.
– bruglesco
2 days ago
add a comment |
Raja Babu is a new contributor. Be nice, and check out our Code of Conduct.
Raja Babu is a new contributor. Be nice, and check out our Code of Conduct.
Raja Babu is a new contributor. Be nice, and check out our Code of Conduct.
Raja Babu is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207063%2fbitmasking-and-searching-consecutive-1s%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
4
Try to give an example with possible value and invalid inputs and expected outputs. it will help people to figure out the way and the purpose of your programme.
– Calak
Nov 6 at 14:52