fork download
  1. #include <string>
  2. #include <cmath>
  3. #include <stdexcept>
  4. using namespace std;
  5. double _string_to_double(string& s, unsigned short radix)
  6. {
  7. std::size_t decimal_pos = s.find('.');
  8. int decimals = 0;
  9. if(decimal_pos != std::string::npos)
  10. {
  11. s.erase(decimal_pos, 1);
  12. decimals = s.size() - decimal_pos;
  13. }
  14. size_t errpos;
  15. double answer = stoll(s, &errpos, radix) / std::pow(radix, decimals);;
  16. if(errpos < s.size())
  17. throw std::invalid_argument("parse error in string_to_double");
  18. return answer;
  19. }
  20.  
  21. int main (){
  22.  
  23. string a = "1844674214124";
  24. for(unsigned long long x = 10000000000000;x>0;--x){
  25. _string_to_double(a,10);
  26. }
  27. return 0;
  28. }
Time limit exceeded #stdin #stdout 5s 3424KB
stdin
Standard input is empty
stdout

Standard output is empty