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