Charnaxuss

CS quest

Apr 12th, 2021
559
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. int parseQuantity(const char * c)
  4. {
  5.     // we can assume that none will create a different Unicode table that does not start with regular part of ASCII code.
  6.  
  7.     // to be clear - we parse count of something, so the number can be only 0 or higher, no place for 0123 or 00003
  8.     // 0123 -> 123 and 00003 -> 3 because we don't need here these 0s.
  9.     // oh, and there will be cases when string is such as long or more as max digits in OS int or even long long
  10.     // but we cant do more than that
  11.     int i = 0;
  12.     while(*c > 47 && *c < 58)
  13.     {
  14.         i = i * 10 + (int)(*c - 48); // it wasnt meant to be fast ;)
  15.         c++;
  16.     }
  17.     return i;
  18. };
  19.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×