fork(2) download
  1. #include <cstring>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int U1ToInt(const char *U1)
  6. {
  7. int ret=0,inv=(*U1=='1');
  8. while(*(++U1)) ret=(ret<<1)+((*U1-'0')^inv);
  9. return inv?-ret:ret;
  10. }
  11.  
  12. int main()
  13. {
  14. cout<<U1ToInt("0111")<<endl;
  15. cout<<U1ToInt("1111")<<endl;
  16. cout<<U1ToInt("010")<<endl;
  17. cout<<U1ToInt("110")<<endl;
  18. cout<<U1ToInt("01")<<endl;
  19. cout<<U1ToInt("11")<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
7
0
2
-1
1
0