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