Created
February 19, 2016 20:33
-
-
Save ademidun/187d460c0419e3334c6a to your computer and use it in GitHub Desktop.
Week3
This file contains 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
int main() { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ | |
int cases, x; | |
//first, we find how many numbers we have, we use scanf on the input from STDIN, to return the number | |
//of cases we have to cases variable | |
scanf("%u", &cases); | |
while(cases--){ | |
//allow n to be tested for each case | |
scanf("%u", &x); | |
//Based on CTCI and frigidrain we can just use the unary negation operator | |
//which is equivalent to: ~n= -(n+1) | |
//this will give us a signed number, so we then convert it to an unsigned representation since we | |
//do not know how c++ will store signed integers | |
printf("%u\n",~(x)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment