Skip to content

Instantly share code, notes, and snippets.

@ademidun
Created February 19, 2016 20:33
Show Gist options
  • Save ademidun/187d460c0419e3334c6a to your computer and use it in GitHub Desktop.
Save ademidun/187d460c0419e3334c6a to your computer and use it in GitHub Desktop.
Week3
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