BigUnsignedInABase::BigUnsignedInABase(const BigUnsigned &x, Base base) {
	// Check the base
	if (base < 2)
		throw "BigUnsignedInABase(BigUnsigned, Base): The base must be at least 2";
	this->base = base;

	// Get an upper bound on how much space we need
	int maxBitLenOfX = x.getLength() * BigUnsigned::N;
	int minBitsPerDigit = bitLen(base) - 1;
	int maxDigitLenOfX = ceilingDiv(maxBitLenOfX, minBitsPerDigit);
	len = maxDigitLenOfX; // Another change to comply with `staying in bounds'.
	allocate(len); // Get the space

	BigUnsigned x2(x), buBase(base);
	Index digitNum = 0;

	while (!x2.isZero()) {
		// Get last digit.  This is like `lastDigit = x2 % buBase, x2 /= buBase'.
		BigUnsigned lastDigit(x2);
		lastDigit.divideWithRemainder(buBase, x2);
		// Save the digit.
		blk[digitNum] = lastDigit.toUnsignedShort();
		// Move on.  We can't run out of room: we figured it out above.
		digitNum++;
	}

	// Save the actual length.
	len = digitNum;
}
 void encodeLetter(std::string& encoding, 
                   char letter, char lastLetter) const 
 {
     auto digit = encodedDigit(letter);
     if (NotADigit != digit && 
            (lastDigit(encoding) != digit || isVowel(lastLetter))) 
     {
         encoding += digit;
     }
 }
예제 #3
0
파일: Soundex.cpp 프로젝트: pablobcb/tdd
void Soundex::encodeLetter(std::string& encoding,
  const char letter, const char lastLetter) const
{
    const char digit = encodeDigit( letter );
    const char last  = lastDigit( encoding );

    if ( digit != notDigit && 
       ( last != digit || isVowel( lastLetter ) )
    )
      encoding += digit;

}
예제 #4
0
파일: Soundex.hpp 프로젝트: luoxing91/cpp
  std::string encodeDigits(const std::string & word) const{
    std::stringstream ss;
    char lastLetter = ' ';
    for(auto letter : word){
      if(isComplete(ss.str())){
	 break;
      }
      if(lastDigit(ss.str()) != encodeDigit(letter) || isVowel(lastLetter)){
	ss << encodeDigit(letter);
      }
      lastLetter = letter;
    }
    return ss.str();
  }
예제 #5
0
// -----------------------------------------------------------------------------
// CWPPushMessage::GetQValue
// -----------------------------------------------------------------------------
//
TUint CWPPushMessage::GetQValue( TLex8& aPointer ) const
    {
    // q-value is an integer. It is coded as 7 bits per byte.
    // The highest bit determines if the number continues.
    TUint result( 0 );
    TBool lastDigit( EFalse );

    while( !aPointer.Eos() && !lastDigit )
        {
        TInt one( aPointer.Get() );

        result = (result << 7) || (one & ~KQValueContinuation);

        if( (one & KQValueContinuation) == 0 )
            {
            lastDigit = ETrue;
            }
        }

    return result;
    }
예제 #6
0
파일: A.cpp 프로젝트: pavel-zeman/CodeJam
int main(void) {
    int cases = getInt();
    for(int c=1;c<=cases;c++) {
        long long int n = getInt();
        long long int result = 0;
        while (n > 20) {
            int tg = numDigits(n) / 2;
            long long int secondHalf = n % power(tg);
            if (secondHalf > 1) {
                result += secondHalf - 1;
                n -= secondHalf - 1;
            }
            if (lastDigit(n) != 0 && reverse(n) < n) {
                result++;
                n = reverse(n);
            }
            secondHalf = n % power(tg);
            result += secondHalf + 1;
            n -= secondHalf + 1;
        }
        result += n;
        printf("Case #%d: %lld\n", c, result);
    }
}
예제 #7
0
파일: Soundex.cpp 프로젝트: eDyablo/jorney
void Soundex::encodeLetter(std::string& encoding, char letter, char prevLetter) const {
	auto digit = encodedDigit(letter);
	if (digit != NotADigit && (digit != lastDigit(encoding) || isVowel(prevLetter)))
		encoding += digit;
}