不久前本人在微博上提交了一道这样的题(via:http://weibo.com/2093492691/xk03lfDxi),许多博友都列出了自己的方法。今天趁有时间,在此整理一下(能力有限,整理不好敬请各位大侠见谅,欢迎提出各路大侠提出更好的方法)。

法一:取反:

  int x;  

  cin>>x;

  cout<<!x<<endl;

法二:条件控制:

  int x; 

  if(x==1)cout<<0<<endl;

  else cout<<1<<endl;

法三:

  int x;

  cin>>x;

  cout<<1-x<<endl;

法四:异或操作

  1 xor x;

法五:

  int x;

  cin >> x;

   cout << (x + 1) % 2 << endl;

相关文章:

  • 2021-04-30
  • 2021-09-08
  • 2022-12-23
  • 2021-11-12
  • 2021-11-19
  • 2022-01-01
  • 2021-10-11
  • 2021-04-16
猜你喜欢
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2021-04-06
相关资源
相似解决方案