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