Problem
http://practice.geeksforgeeks.org/problems/toggle-bits-given-range/0
Solution
http://practice.geeksforgeeks.org/problems/toggle-bits-given-range/0
Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
using namespace std; | |
int main(int argc, char** argv) { | |
int t; | |
int N,L,R; | |
cin>>t;// test cases | |
for(int i=0;i<t;i++) | |
{ | |
cin>>N>>L>>R; | |
for(int i=L-1;i<R;i++) | |
{ | |
N^=1<<i; | |
} | |
cout<<N<<endl; | |
} | |
return 0; | |
} |
No comments:
Post a Comment