/* ** Parse a timezone extension on the end of a date-time. ** The extension is of the form: ** ** (+/-)HH:MM ** ** If the parse is successful, write the number of minutes ** of change in *pnMin and return 0. If a parser error occurs, ** return 0. ** ** A missing specifier is not considered an error. */ static int parseTimezone(const char *zDate, DateTime *p){ int sgn = 0; int nHr, nMn; while( isspace(*zDate) ){ zDate++; } p->tz = 0; if( *zDate=='-' ){ sgn = -1; }else if( *zDate=='+' ){ sgn = +1; }else{ return *zDate!=0; } zDate++; nHr = getDigits(zDate, 2); if( nHr<0 || nHr>14 ) return 1; zDate += 2; if( zDate[0]!=':' ) return 1; zDate++; nMn = getDigits(zDate, 2); if( nMn<0 || nMn>59 ) return 1; zDate += 2; p->tz = sgn*(nMn + nHr*60); while( isspace(*zDate) ){ zDate++; } return *zDate!=0; }
/* ** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF. ** The HH, MM, and SS must each be exactly 2 digits. The ** fractional seconds FFFF can be one or more digits. ** ** Return 1 if there is a parsing error and 0 on success. */ static int parseHhMmSs(const char *zDate, DateTime *p){ int h, m, s; double ms = 0.0; h = getDigits(zDate, 2); if( h<0 || zDate[2]!=':' ) return 1; zDate += 3; m = getDigits(zDate, 2); if( m<0 || m>59 ) return 1; zDate += 2; if( *zDate==':' ){ s = getDigits(&zDate[1], 2); if( s<0 || s>59 ) return 1; zDate += 3; if( *zDate=='.' && isdigit(zDate[1]) ){ double rScale = 1.0; zDate++; while( isdigit(*zDate) ){ ms = ms*10.0 + *zDate - '0'; rScale *= 10.0; zDate++; } ms /= rScale; } }else{ s = 0; } p->validJD = 0; p->validHMS = 1; p->h = h; p->m = m; p->s = s + ms; if( parseTimezone(zDate, p) ) return 1; p->validTZ = p->tz!=0; return 0; }
/* ** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF. ** The HH, MM, and SS must each be exactly 2 digits. The ** fractional seconds FFFF can be one or more digits. ** ** Return 1 if there is a parsing error and 0 on success. */ static int parseHhMmSs(const char *zDate, DateTime *p){ int h, m, s; double ms = 0.0; if( getDigits(zDate, "20c:20e", &h, &m)!=2 ){ return 1; } zDate += 5; if( *zDate==':' ){ zDate++; if( getDigits(zDate, "20e", &s)!=1 ){ return 1; } zDate += 2; if( *zDate=='.' && sqlite3Isdigit(zDate[1]) ){ double rScale = 1.0; zDate++; while( sqlite3Isdigit(*zDate) ){ ms = ms*10.0 + *zDate - '0'; rScale *= 10.0; zDate++; } ms /= rScale; } }else{ s = 0; } p->validJD = 0; p->validHMS = 1; p->h = h; p->m = m; p->s = s + ms; if( parseTimezone(zDate, p) ) return 1; p->validTZ = (p->tz!=0)?1:0; return 0; }
/* ** Parse dates of the form ** ** YYYY-MM-DD HH:MM:SS.FFF ** YYYY-MM-DD HH:MM:SS ** YYYY-MM-DD HH:MM ** YYYY-MM-DD ** ** Write the result into the DateTime structure and return 0 ** on success and 1 if the input string is not a well-formed ** date. */ static int parseYyyyMmDd(const char *zDate, DateTime *p){ int Y, M, D; Y = getDigits(zDate, 4); if( Y<0 || zDate[4]!='-' ) return 1; zDate += 5; M = getDigits(zDate, 2); if( M<=0 || M>12 || zDate[2]!='-' ) return 1; zDate += 3; D = getDigits(zDate, 2); if( D<=0 || D>31 ) return 1; zDate += 2; while( isspace(*zDate) ){ zDate++; } if( isdigit(*zDate) ){ if( parseHhMmSs(zDate, p) ) return 1; }else if( *zDate==0 ){ p->validHMS = 0; }else{ return 1; } p->validJD = 0; p->validYMD = 1; p->Y = Y; p->M = M; p->D = D; if( p->validTZ ){ computeJD(p); } return 0; }
bool haveSameDigits(unsigned long long a,unsigned long long b) { std::vector<unsigned long long> v1 = getDigits(a); std::vector<unsigned long long> v2 = getDigits(b); for(int i = 0; i<10; i++) { if(v1.at(i)!=v2.at(i)) { return false; } } return true; }
int SearchDigit(short int Pos, short int Associacao[][TAM_A], char Codigo[][TAM_S]) { short int D1, D2, D3, D4, R, i=0; do{ getDigits(Codigo[i][Pos], &D1, &D2, Associacao[i]); getDigits(Codigo[i+1][Pos], &D3, &D4, Associacao[i+1]); i++; R = Compare(D1, D2, D3, D4); }while( R == UNDEFINED ); return R; }
// // Set Bin Width property by setting the slider // void HistogramWindow::setBin(double x) { if (bactive) return; bactive = true; binWidthSlider->setValue(x/getDelta()); rBinSlider->setValue(x/getDelta()); binWidthLineEdit->setText(QString("%1").arg(x, 0, 'f', getDigits())); rBinEdit->setText(QString("%1").arg(x, 0, 'f', getDigits())); powerHist->setBinWidth(x); bactive = false; // redraw stale = true; updateChart(); }
void RRTime::digitalClockDisplay(){ // digital clock display of the time DEBUGPRINT.print(hour()); DEBUGPRINT.print(":"); DEBUGPRINT.print(getDigits(minute())); DEBUGPRINT.print(":"); DEBUGPRINT.print(getDigits(second())); DEBUGPRINT.print(" "); DEBUGPRINT.print(day()); DEBUGPRINT.print("."); DEBUGPRINT.print(month()); DEBUGPRINT.print("."); DEBUGPRINT.print(year()); DEBUGPRINT.println(); }
QString RealFormat::doFormat(const Variant& val) const { QString result; const LongReal* vr = dynamic_cast<const LongReal*>((const VariantData*)val); if (!vr) return result; if (vr->isNaN()) return formatNaN(); if (vr->isZero()) return formatZero(); int usedigits = significandbase == base || precision == 0? getDigits() : (precision - 1) / _digitsz(base) + 1; RawFloatIO RawFloatIO = vr->convert(usedigits, mode, base); if (RawFloatIO.error != Success) return result; result = getSignificandPrefix(RawFloatIO) + formatInt(RawFloatIO) + formatFrac(RawFloatIO) + getSignificandSuffix(RawFloatIO); if (useScale(RawFloatIO)) result += getScalePrefix(RawFloatIO) + formatScale(RawFloatIO) + getScaleSuffix(RawFloatIO); return result; }
QString RealFormat::fracPart(const RawFloatIO& io) const { if (significandbase == base || precision == 0) return io.fracpart; return changeBase(_digitsz(base), _digitsz(significandbase), getDigits(), io.fracpart, 0, lowerCaseHexDigit); }
//------------------------------------------------------------------------------ // operator<< //------------------------------------------------------------------------------ std::ostream& operator<<(std::ostream& sout, const Matrix& m) { if (!m.isGoodMatrix()) { sout << "There is a problem displaying this matrix." << std::endl; } else { const unsigned int DECPNT = m.getDecPoint(); const unsigned int DPZERO = (DECPNT == 0 ? -1 : 0); const unsigned int DIGITS = getDigits(m.getMaxMag()); const unsigned int MARGIN = 3; const unsigned int FLDWTH = DECPNT + DPZERO + DIGITS + MARGIN; std::ios_base::fmtflags oldFmtFlgs = sout.flags(); std::streamsize oldprec = sout.precision(); sout << std::setprecision(DECPNT) << std::setiosflags(std::ios::fixed); for (unsigned int i=0; i<m.rows; i++) { for (unsigned int j=0; j<m.cols; j++) { sout << std::setw(FLDWTH) << m[i][j]; } sout << std::endl; } sout.setf(oldFmtFlgs); sout << std::setprecision(oldprec); } return sout; }
/* ** Parse dates of the form ** ** YYYY-MM-DD HH:MM:SS.FFF ** YYYY-MM-DD HH:MM:SS ** YYYY-MM-DD HH:MM ** YYYY-MM-DD ** ** Write the result into the DateTime structure and return 0 ** on success and 1 if the input string is not a well-formed ** date. */ static int parseYyyyMmDd(const char *zDate, DateTime *p){ int Y, M, D, neg; if( zDate[0]=='-' ){ zDate++; neg = 1; }else{ neg = 0; } if( getDigits(zDate, "40f-21a-21d", &Y, &M, &D)!=3 ){ return 1; } zDate += 10; while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; } if( parseHhMmSs(zDate, p)==0 ){ /* We got the time */ }else if( *zDate==0 ){ p->validHMS = 0; }else{ return 1; } p->validJD = 0; p->validYMD = 1; p->Y = neg ? -Y : Y; p->M = M; p->D = D; if( p->validTZ ){ computeJD(p); } return 0; }
void GUIScene_Game::printNumber(const int x, const iPoint position, const Gauntlet_Colors color){ vector<int>* digits = new vector<int>(); getDigits(x, digits); for (int i = 0; i < digits->size(); i++) App->renderer->Blit(interfaceGraphics, position.x - (7 * (digits->size() - i - 1)), position.y, &numbers[color][digits->at(i)], 0.0F); delete digits; }
void GUIScene_Game::getDigits(const int x, vector<int>* digits) { if (x >= 10) getDigits(x / 10, digits); digits->push_back(x % 10); }
/* ** Parse a timezone extension on the end of a date-time. ** The extension is of the form: ** ** (+/-)HH:MM ** ** Or the "zulu" notation: ** ** Z ** ** If the parse is successful, write the number of minutes ** of change in p->tz and return 0. If a parser error occurs, ** return non-zero. ** ** A missing specifier is not considered an error. */ static int parseTimezone(const char *zDate, DateTime *p){ int sgn = 0; int nHr, nMn; int c; while( sqlite3Isspace(*zDate) ){ zDate++; } p->tz = 0; c = *zDate; if( c=='-' ){ sgn = -1; }else if( c=='+' ){ sgn = +1; }else if( c=='Z' || c=='z' ){ zDate++; goto zulu_time; }else{ return c!=0; } zDate++; if( getDigits(zDate, "20b:20e", &nHr, &nMn)!=2 ){ return 1; } zDate += 5; p->tz = sgn*(nMn + nHr*60); zulu_time: while( sqlite3Isspace(*zDate) ){ zDate++; } p->tzSet = 1; return *zDate!=0; }
int64_t Problem24::solve() { auto digits = getDigits(123456789); digits.insert(digits.begin(), 0); for(int i = 1; i < 1000000; ++i) std::next_permutation(digits.begin(), digits.end()); return digitsToNumber(digits.begin(), digits.end()); }
long int reverse(long int number){ long int num = 0; int digits = getDigits(number); for(int i = 1; i <= digits; i++){ long int tmp = number % myPow(10, 1); number = number / 10; num += tmp * myPow(10, digits-i); } return num; }
int getSmallest(int number, int k) { long long base = getDigits(number); long long res = 0; long long offset = 1; for (int copy = 1; copy <= 100005; copy++) { res += offset * (number%k); res %= k; offset = (offset*base) % k; if (res == 0) return copy; } return -1; }
// // We need to config / update the controls when data series/metrics change // void HistogramWindow::setBinEditors() { // the line edit validator QValidator *validator; if (getDigits() == 0) { validator = new QIntValidator(binWidthSlider->minimum() * getDelta(), binWidthSlider->maximum() * getDelta(), binWidthLineEdit); } else { validator = new QDoubleValidator(binWidthSlider->minimum() * getDelta(), binWidthSlider->maximum() * getDelta(), getDigits(), binWidthLineEdit); } binWidthLineEdit->setValidator(validator); rBinEdit->setValidator(validator); }
int Utilities :: getSumDigits(int num) { int sum = 0; vector<int> digits = getDigits(num); for (vector<int>::iterator iter = digits.begin(); iter != digits.end(); iter++) { sum += *iter; } return sum; }
void Score::draw(sf::RenderTarget& target, sf::RenderStates states) const { std::string temp = std::to_string(score); int x(xPos); for(int i(0); i < getDigits(score); i++) { int a = const_cast<Score*>(this)->setFirstDigitsPos(temp, x); target.draw(nums[a], states); temp.erase(0,1); x+= 12; } }
std::vector<int64_t> Problem35::getRotations(int64_t num) { std::vector<int64_t> output; auto digits = getDigits(num); int count = (int)digits.size(); for(int i = 0; i < count; ++i) { int total = 0; for(int j = 0; j < count; ++j) total += (int)pow(10, count - j - 1) * digits[(j + i) % count]; output.push_back(total); } return output; }
//------------------------------------------------------------------------------ // showMatrix //------------------------------------------------------------------------------ void Matrix::showMatrix(const unsigned int DP, const unsigned int FW) const { if (!isGoodMatrix()) { std::cout << "There is a problem displaying this matrix." << std::endl; } else { unsigned int decpnt = getDecPoint(); if (DP != decpnt) { decpnt = DP; } unsigned int fldwth = 0; unsigned int gfw = getFldWidth(); unsigned int margin = 3; unsigned int sum = decpnt; sum += (decpnt == 0 ? -1 : 0); sum += getDigits(getMaxMag()); sum += margin; if (sum <= gfw) { fldwth = gfw; } else if (sum <= FW) { fldwth = FW; } else { fldwth = sum; } std::ios_base::fmtflags oldFmtFlgs = std::cout.flags(); std::streamsize oldprec = std::cout.precision(); std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(decpnt); for (unsigned int i=0; i<rows; i++) { for (unsigned int j=0; j<cols; j++) { unsigned int idx = cols*i + j; std::cout << std::setw(fldwth) << mda[idx]; } std::cout << std::endl; } std::cout.setf(oldFmtFlgs); std::cout << std::setprecision(oldprec); } }
// // When user selects a different data series // void HistogramWindow::seriesChanged() { // series changed so tell power hist powerHist->setSeries(static_cast<RideFile::SeriesType>(seriesCombo->itemData(seriesCombo->currentIndex()).toInt())); powerHist->setDelta(getDelta()); powerHist->setDigits(getDigits()); // now update the slider stepper and linedit setBinEditors(); // set an initial bin width value setBin(getDelta()); // replot stale = true; updateChart(); }
void HistogramWindow::treeSelectionTimeout() { // new metric chosen, so set up all the bin width, line edit // delta, precision etc powerHist->setSeries(RideFile::none); powerHist->setDelta(getDelta()); powerHist->setDigits(getDigits()); // now update the slider stepper and linedit setBinEditors(); // initial value -- but only if need to double minbinw = getDelta(); double maxbinw = getDelta() * 100; double current = binWidthLineEdit->text().toDouble(); if (current < minbinw || current > maxbinw) setBin(getDelta()); // replot updateChart(); }
bool isHappy(int n) { int sum = n; int cnt = 1; while (true){ int temp = 0; stack<int> digits = getDigits(sum); cnt++; while (!digits.empty()) { int n = digits.top(); temp += n * n; digits.pop(); } if (temp == 1) break; else { sum = temp; } if (cnt > 42) return false; // hardcoded the hault condition, I do not know how to mathmatically prove, but a magic number } return true; }
int64_t Problem79::solve() { std::set<int> combinations = parseInput(); std::set<DirectedEdge> uniqueEdges; for(auto &i : combinations) { auto digits = getDigits(i); for(int j = 0; j < digits.size() - 1; ++j) uniqueEdges.insert(DirectedEdge(digits[j], digits[j + 1], 0)); } WeightedDigraph digraph(10); for(auto &i : uniqueEdges) digraph.addEdge(i); TopologicalSort sort(digraph); auto result = sort.result(); return digitsToNumber(result.begin(), result.end()); }
SWITCH_DECLARE(char *) CoreSession::getDigits(int maxdigits, char *terminators, int timeout) { return getDigits(maxdigits, terminators, timeout, 0); }
int numDupDigitsAtMostN(int N) { getDigits(N); memset(dp, -1, sizeof(dp)); return solve(0, false, 0, false, true); }
bool Utilities :: isPanditigalNumber(int n, long long num, bool includeZero) { return isPanditigalNumber(n, getDigits(num), false); }