I think this should do:
string s;
cin >> s;
int n = s.length(), i;
for(i=n-1; s[i]=='0'; --i);//find the fist set bit from right...
for(int j=--i; j>=0; --j){// complement rest of the bits...
if(s[j] == '0')
s[j] = '1';
else
s[j] = '0';
}
cout << s << endl;
On 26 October 2012 03:40, rahul sharma <[email protected]> wrote:
> Plz give a program for this...thnx
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.