yashsheth46
BAN USERint countInt(int n){
int count = 0;
while(n){
n&=n-1;
count++;
}
return count;
}
mask = (~0<<j)|(~(~0<<i-1));
N = (N&mask)|(M<<i-1);
So did you find a match? I might be in a similar situation, please share your experience. Thanks!
- yashsheth46 February 27, 2012string nextNumber (string str){
if(str==NULL)
return str;
int pos = str.length();
int carry = 0;
while(pos>=0){
if(!isnum(str[pos]) && pos > 0) //first char can be '-'
return NULL;
if(str[pos] == '9') {
if(str[0] == '-') {
str[pos]--;
pos--;
}
else{
str[pos] = 0;
if(pos==0){
str.resize(str.length+1);
str.insert(0,0); //insert 0 at the first position which will be incremented in the next iteration
}
else pos--; //decrement only if pos != 0
}
} // shut the first else after checking for negative number
else{
if(str[0] == '-' && str[pos] == '0') {
if(pos == 1){
string str1 = "-";
str1.append(str.begin()+2, str.end);
str = str1; break;
}
str[pos] = 9;
pos--;
}
else{
str[pos]++;
break;
}
}
}
return str;
}
string nextNumber (string str){
if(str==NULL)
return str;
int pos = str.length();
int carry = 0;
while(pos>=0){
if(!isnum(str[pos]) && pos > 0) //first char can be '-'
return NULL;
if(str[pos] == '9') {
if(str[0] == '-') {
str[pos]--;
pos--;
}
else{
str[pos] = 0;
if(pos==0){
str.resize(str.length+1);
str.insert(0,0); //insert 0 at the first position which will be incremented in the next iteration
}
else pos--; //decrement only if pos != 0
}
} // shut the first else after checking for negative number
else{
if(str[0] == '-' && str[pos] == '0') {
if(pos == 1){
string str1 = "-";
str1.append(str.begin()+2, str.end);
str = str1; break;
}
str[pos] = 9;
pos--;
}
else{
str[pos]++;
break;
}
}
}
return str;
}
string nextNumber (string str){
if(str==NULL)
return str;
int pos = str.length();
int carry = 0;
while(pos>=0){
if(!isnum(str[pos]) && pos > 0) //first char can be '-'
return NULL;
if(str[pos] == '9') {
if(str[0] == '-') {
str[pos]--;
pos--;
}
else{
str[pos] = 0;
if(pos==0){
str.resize(str.length+1);
str.insert(0,0); //insert 0 at the first position which will be incremented in the next iteration
}
else pos--; //decrement only if pos != 0
}
} // shut the first else after checking for negative number
else{
if(str[0] == '-' && str[pos] == '0') {
if(pos == 1){
string str1 = "-";
str1.append(str.begin()+2, str.end);
str = str1; break;
}
str[pos] = 9;
pos--;
}
else{
str[pos]++;
break;
}
}
}
return str;
}
string nextNumber (string str){
if(str==NULL)
return str;
int pos = str.length();
int carry = 0;
while(pos>=0){
if(!isnum(str[pos]) && pos > 0) //first char can be '-'
return NULL;
if(str[pos] == '9') {
if(str[0] == '-') {
str[pos]--;
pos--;
}
else{
str[pos] = 0;
if(pos==0){
str.resize(str.length+1);
str.insert(0,0); //insert 0 at the first position which will be incremented in the next iteration
}
else pos--; //decrement only if pos != 0
}
} // shut the first else after checking for negative number
else{
if(str[0] == '-' && str[pos] == '0') {
if(pos == 1){
string str1 = "-";
str1.append(str.begin()+2, str.end);
str = str1; break;
}
str[pos] = 9;
pos--
}
else{
str[pos]++;
break;
}
}
}
return str;
}
string nextNumber (string str){
if(str==NULL)
return str;
int pos = str.length();
int carry = 0;
while(pos>=0){
if(!isnum(str[pos]) && pos > 0) //first char can be '-'
return NULL;
if(str[pos] == '9') {
if(str[0] == '-') {
str[pos]--;
pos--;
}
else{
str[pos] = 0;
if(pos==0){
str.resize(str.length+1);
str.insert(0,0); //insert 0 at the first position which will be incremented in the next iteration
}
else pos--; //decrement only if pos != 0
}
} // shut the first else after checking for negative number
else{
if(str[0] == '-' && str[pos] == '0') {
if(pos == 1){
string str1 = "-";
str1.append(str.begin()+2, str.end);
str = str1; break;
}
str[pos] = 9;
pos--
}
else{
str[pos]++;
break;
}
}
}
return str;
}
string nextNumber (string str){
if(str==NULL)
return str;
int pos = str.length();
int carry = 0;
while(pos>=0){
if(!isnum(str[pos]))
return NULL;
if(str[pos] == '9') {
str[pos] = 0;
if(pos==0){
str.resize(str.length+1);
str.insert(0,0); //insert 0 at the first position which will be incremented in the next iteration
}
else pos--; //decrement only if pos != 0
}
else{
str[pos]++;
break;
}
}
return str;
}
string nextNumber (string str){
if(str==NULL)
return str;
int pos = str.length();
int carry = 0;
while(pos>=0){
if(!isnum(str[pos]))
return NULL;
if(str[pos] == '9') {
str[pos] = 0;
if(pos==0){
str.resize(str.length+1);
str.insert(0,0); //insert 0 at the first position which will be incremented in the next iteration
}
else pos--; //decrement only if pos != 0
}
else{
str[pos]++;
break;
}
}
return str;
}
string nextNumber (string str){
if(str==NULL)
return str;
int pos = str.length();
int carry = 0;
while(pos>=0){
if(!isnum(str[pos]))
return NULL;
if(str[pos] == '9') {
str[pos] = 0;
if(pos==0){
str.resize(str.length+1);
str.insert(0,0); //insert 0 at the first position which will be incremented in the next iteration
}
else pos--; //decrement only if pos != 0
}
else{
str[pos]++;
break;
}
}
return str;
}
}
- yashsheth46 March 09, 2012