Пример #1
0
char *asctime(const struct tm *tp) {
  static char cbuf[26];
  char *cp;
  char *ncp;
  const int *ip;

  cp = cbuf;
  for (ncp = "Day Mon 00 00:00:00 1900\n"; *cp++ = *ncp++;) ;
  ncp = &"SunMonTueWedThuFriSat"[3 * tp->tm_wday];
  cp = cbuf;
  *cp++ = *ncp++;
  *cp++ = *ncp++;
  *cp++ = *ncp++;
  cp++;
  ip = &tp->tm_mon;
  ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*ip)*3];
  *cp++ = *ncp++;
  *cp++ = *ncp++;
  *cp++ = *ncp++;
  cp = twoDigits(cp, *--ip);
  cp = twoDigits(cp, *--ip+100);
  cp = twoDigits(cp, *--ip+100);
  cp = twoDigits(cp, *--ip+100);
  if (tp->tm_year >= 100) {
    cp[1] = '2';
    cp[2] = '0';
  }
  cp += 2;
  cp = twoDigits(cp, tp->tm_year + 100);
  return cbuf;
}
 string threeDigits(const int& num, const unordered_map<int, string>& lookup, const string& unit) {
     vector<string> res;
     if (num / 100) {
         res.emplace_back(lookup.find(num / 100)->second + " " + "Hundred");
     }
     if (num % 100) {
         res.emplace_back(twoDigits(num % 100, lookup));
     }
     if (!unit.empty()) {
         res.emplace_back(unit);
     }
     return join(res, " ");
 }