fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  
  6. int na10(string dana) {
  7. int pom =0;
  8. int dl=dana.length();
  9. for (int i=0; i<dl; i++){
  10. int x = int(dana[dl-i-1]) -48;
  11. pom = pom +x*pow(2,i);
  12.  
  13. }
  14. return pom;
  15. }
  16. int main() {
  17. cout<<na10("101010")<<endl;
  18. cout<<na10("110101")<<endl;
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
42
53