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. int x = int(dana[dl-i-1]) -48;
  15.  
  16. pom = pom +x*pow(2,i);
  17.  
  18. }
  19. return pom;
  20. }
  21.  
  22. int main() {
  23.  
  24. cout<<na10("101010")<<endl;
  25. cout<<na10("110101")<<endl;
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
42
53