コード例 #1
0
ファイル: 10093.C プロジェクト: azim-khan/UVA-Solutions
int main ()
{
    int i;
    while ( scanf ("%s", input) == 1 ) {

        len_input = strlen (input);
        if ( input [0]=='+'||input [0]=='-' ){
            for ( i = 1; i <= len_input; i++ )
                input [i - 1] = input [i];

                len_input = strlen (input);
            }

        int baseFound = 0;

        int sum = 0;

        for ( i = 0; i < len_input; i++ )
            sum += getVal (input [i]);

        for ( i = findBase(); i <= 62; i++ ) {
            if ( sum % (i - 1) == 0 ) {
                printf ("%d\n", i);
                baseFound = 1;
                break;
            }
        }

        if ( baseFound==0 )
            printf ("such number is impossible!\n");
    }

    return 0;
}
コード例 #2
0
ファイル: roxiemem.hpp プロジェクト: afishbeck/HPCC-Platform
 static unsigned getAllocatorId(const void *ptr)
 {
     dbgassertex(ptr);
     HeapletBase *h = findBase(ptr);
     unsigned id = h->_rawAllocatorId(ptr);
     return (id & ACTIVITY_MASK);
 }
コード例 #3
0
ファイル: roxiemem.hpp プロジェクト: afishbeck/HPCC-Platform
 static void release(const void *ptr)
 {
     if (ptr)
     {
         HeapletBase *h = findBase(ptr);
         h->noteReleased(ptr);
     }
 }
コード例 #4
0
ファイル: roxiemem.hpp プロジェクト: afishbeck/HPCC-Platform
 static bool isShared(const void *ptr)
 {
     if (ptr)
     {
         HeapletBase *h = findBase(ptr);
         return h->_isShared(ptr);
     }
     // isShared(NULL) or isShared on an object that shares a link-count is an error
     throwUnexpected();
 }
コード例 #5
0
ファイル: roxiemem.hpp プロジェクト: afishbeck/HPCC-Platform
 static size32_t capacity(const void *ptr)
 {
     if (ptr)
     {
         HeapletBase *h = findBase(ptr);
         //MORE: If capacity was always the size stored in the first word of the block this could be non virtual
         //and the whole function could be inline.
         return h->_capacity();
     }
     throwUnexpected();
 }
コード例 #6
0
ファイル: main.c プロジェクト: sonamwan/codecon
int convertValue(char *conValue){
    int b=findBase(conValue);
    int c=strlen(conValue);
    int k=0;
    int i;
    for(i=c-1; i>=0; i--) {
        k+=coefficient(conValue, i)*coefadd(b, c-i-1);
    }
//    printf("K Value: %d\n", k);
    return k;
}
コード例 #7
0
ファイル: geohash.cpp プロジェクト: alabid/cpp11geohash
const string GeoHasherBaseX::toChars(const char* map, uint64_t intHash) {
  int base = findBase(map);

  string ret {};
  int h, i;
  int curBit = 0;
  uint64_t baseMax = strlen(map)-1;

  while (curBit < bitDepth) {
    h = ((baseMax << curBit) & intHash) >> curBit;
    ret = map[h] + ret;
    curBit += base;
  }

  return ret;
}
コード例 #8
0
ファイル: base_manager.cpp プロジェクト: caocao/slvoice
void BaseManager::remove(const string& handle) {

	try {
		BaseInfo* info = findBase(handle);

		if (info != NULL) {
			handles.erase(info->id);
			infos.erase(handle);
			delete info;
			g_logger->Info("BaseManager") << "Removed Info handle=" << handle << endl;
		}
	}
	catch (exception e) {
		g_logger->Fatal("BaseManager") << "Error in convertId " << e.what() << endl;
		throw e;
	}
}
コード例 #9
0
ファイル: geohash.cpp プロジェクト: alabid/cpp11geohash
const uint64_t GeoHasherBaseX::toInt(const char* map, string sHash) {
  int base = findBase(map);
  uint64_t intHash = 0, 
    pos;
  int curBit = 0;
  const char* mapPtr;
  char ch;

  for (int i = sHash.size()-1; i >= 0; i--) {
    mapPtr = map;
    ch = sHash[i];
    while (*mapPtr++ != ch);

    pos = mapPtr - map - 1;
    intHash |= pos << curBit;
    curBit += base;
  }

  return intHash;
}
コード例 #10
0
ファイル: roxiemem.hpp プロジェクト: afishbeck/HPCC-Platform
 static void link(const void *ptr)
 {
     HeapletBase *h = findBase(ptr);
     h->noteLinked(ptr);
 }
コード例 #11
0
ファイル: account_manager.cpp プロジェクト: caocao/slvoice
AccountInfo* AccountManager::find(const string& handle) {
	return (AccountInfo *)findBase(handle);
}
コード例 #12
0
ファイル: roxiemem.hpp プロジェクト: afishbeck/HPCC-Platform
 static bool hasDestructor(const void *ptr)
 {
     dbgassertex(ptr);
     HeapletBase *h = findBase(ptr);
     return h->_hasDestructor(ptr);
 }
コード例 #13
0
ファイル: harfbuzz-myanmar.c プロジェクト: 4Fwolf/mt6572_x201
// Porting the pango-myanmar module for reordering a syllable correctly when shape it.
static HB_Bool myanmar_shape_syllable(HB_Bool openType, HB_ShaperItem *item, HB_Bool invalid)
{
    /*
//    MMDEBUG("\nsyllable from %d len %d, str='%s'", item->item.pos, item->item.length,
//      item->string->mid(item->from, item->length).toUtf8().data());
    */

#ifndef NO_OPENTYPE
    const int availableGlyphs = item->num_glyphs;
#endif
    const HB_UChar16 *uc = item->string + item->item.pos;
    int vowel_e = -1;
    int kinzi = -1;
    int medial_ra = -1;
    int i;
    int len = 0;
    unsigned short reordered[32];
    unsigned char properties[32];
    enum {
        AboveForm = 0x01, PreForm = 0x02, PostForm = 0x04, BelowForm = 0x08
    };

    memset(properties, 0, 32*sizeof(unsigned char));

    /* according to the table the max length of a syllable should be around 14 chars */
    assert(item->item.length < 32);

#ifdef MYANMAR_DEBUG
    printf("original:");
    for (i = 0; i < (int)item->item.length; i++) {
        MMDEBUG("    %d: %4x", i, uc[i]);
    }
#endif

    len = 0;
    MymrCharClass char_class;
    int basE = 0, cursor = 0;
    while (basE < (int)item->item.length) {
        medial_ra = -1;  /* There is no Medial Ra, if found this value will change */
        kinzi = -1; /* There is no Kinzi, if found this value will change */
        if (getMyanmarCharClass(uc[cursor]) & Mymr_CF_VIRAMA)
            basE = findBase(uc, cursor, (int)item->item.length);
        else
            basE = findBase(uc, cursor + 1, (int)item->item.length);

        for (i = cursor; i < basE; i += 1) {
            char_class = getMyanmarCharClass(uc[i]);

            /* look for kinzi and remember position */
            if (((char_class & Mymr_CF_CLASS_MASK) == Mymr_CC_NGA) && (i + 2 < basE)
                    && ((getMyanmarCharClass(uc[i + 1]) & Mymr_CF_CLASS_MASK) == Mymr_CC_ASAT)
                    && (getMyanmarCharClass(uc[i + 2]) & Mymr_CF_VIRAMA)) {
                if (i + 3 == (int)item->item.length) {
                    reordered[len] = Mymr_C_DOTTED_CIRCLE;
                    len += 1;
                } else if (getMyanmarCharClass(uc[i + 3]) & Mymr_CF_CONSONANT) {
                    kinzi = i;
                    cursor += 3;
                }
            }

            /* if vowel e, wirte it out */
            if (i > 0 && ((getMyanmarCharClass(uc[i -1]) & Mymr_CF_CLASS_MASK) != Mymr_CC_CONSONANT)
                    && (char_class & Mymr_CF_DEP_VOWEL) && (char_class & Mymr_CF_POS_BEFORE)) {
                reordered[len] = Mymr_C_VOWEL_E;
                properties[len] = PostForm;
                len += 1;
            }

            /* look for medial ra and remember position */
            if ((char_class & Mymr_CF_CLASS_MASK) == Mymr_CC_MEDIAL_R) {
                medial_ra = i;
            }
        }

        /* write medial ra if found  */
        if (medial_ra > -1) {
            reordered[len] = Mymr_C_MEDIAL_R;
            properties[len] = PreForm;
            len += 1;
        }

        /* shall we add a dotted circle?
         * If in the position in which the base should be (first char in the string) there is
         * a character that has the Dotted circle flag (a character that cannot be a base)
         * then write a dotted circle
         */
        if (getMyanmarCharClass(uc[cursor]) & Mymr_CF_DOTTED_CIRCLE) {
            /* add dotted circle */
            reordered[len] = Mymr_C_DOTTED_CIRCLE;
            len += 1;
        }

        /* copy what is left to the output, skipping before vowels and
         * medial Ra if they are present
         */
        for (i = cursor; i < basE; i += 1) {
            char_class = getMyanmarCharClass(uc[i]);

            /* skip vowel e, it was already processed */
            if (i > 0 && ((getMyanmarCharClass(uc[i -1]) & Mymr_CF_CLASS_MASK) != Mymr_CC_CONSONANT)
                    &&(char_class & Mymr_CF_DEP_VOWEL) && (char_class & Mymr_CF_POS_BEFORE)) {
                continue;
            }

            /* skip medial ra, it was already processed */
            if (i == medial_ra) {
                continue;
            }

            switch (char_class & Mymr_CF_POS_MASK) {
            case Mymr_CF_POS_ABOVE:
                reordered[len] = uc[i];
                properties[len] = AboveForm;
                len += 1;
                break;

            case Mymr_CF_POS_AFTER:
                reordered[len] = uc[i];
                properties[len] = PostForm;
                len += 1;
                break;

            case Mymr_CF_POS_BELOW:
                reordered[len] = uc[i];
                properties[len] = BelowForm;
                len += 1;
                break;

            default:
                /* assign the correct flags to Medials */
                if ((char_class & Mymr_CF_MEDIAL) && i + 1 < basE) {
                    if ((char_class & Mymr_CF_CLASS_MASK) == Mymr_CC_MEDIAL_Y) { /* medial ya which possess below and right */
                        reordered[len] = uc[i];
                        properties[len] = PostForm;
                        len += 1;
                        break;
                    } else { /* others wa, ha only below */
                        reordered[len] = uc[i];
                        properties[len] = BelowForm;
                        len += 1;
                        break;
                    }
                }

                if ((char_class & Mymr_CF_VIRAMA) && i + 1 < basE) {
                    if ((getMyanmarCharClass(uc[i + 1]) & Mymr_CF_CLASS_MASK) == Mymr_CC_CONSONANT) { /* subscript consonant */
                        reordered[len] = uc[i];
                        properties[len] = BelowForm;
                        len += 1;
                        break;
                    }
                }

                /* assign the correct flags to consonant with subscript consonant */
                if ((char_class & Mymr_CF_CONSONANT) && i + 2 < basE) {
                    if ((getMyanmarCharClass(uc[i + 1]) & Mymr_CF_VIRAMA)
                            && (getMyanmarCharClass(uc[i + 2]) & Mymr_CF_CLASS_MASK) == Mymr_CC_CONSONANT) {
                        reordered[len] = uc[i];
                        properties[len] = BelowForm;
                        len += 1;
                        break;
                    }
                }

                /* kinzi_to_be */
                if (((char_class & Mymr_CF_CLASS_MASK) == Mymr_CC_NGA)
                        && (getMyanmarCharClass(uc[i + 1]) & Mymr_CF_ASAT)
                        && (getMyanmarCharClass(uc[i + 2]) & Mymr_CF_VIRAMA)
                        ) {
                    reordered[len] = uc[i];
                    i += 1;
                    reordered[len + 1] = uc[i];
                    i += 1;
                    reordered[len + 2] = uc[i];
                    properties[len] = AboveForm;
                    properties[len + 1] = AboveForm;
                    properties[len + 2] = AboveForm;
                    len += 3;
                    break;
                }

                /* default - any others */
                reordered[len] = uc[i];
                len += 1;
                break;
            }/* switch */

            if (kinzi > -1 && i == cursor) {
                reordered[len] = Mymr_C_NGA;
                reordered[len + 1] = Mymr_C_ASAT;
                reordered[len + 2] = Mymr_C_VIRAMA;
                properties[len] = AboveForm;
                properties[len + 1] = AboveForm;
                properties[len + 2] = AboveForm;
                len += 3;
            }
        } /* for: loop for a baseE */
        cursor = basE;
    } /* while: loop for a syllable*/

    if (!item->font->klass->convertStringToGlyphIndices(item->font,
                                                        reordered, len,
                                                        item->glyphs, &item->num_glyphs,
                                                        item->item.bidiLevel % 2))
        return FALSE;

    MMDEBUG("after shaping: len=%d", len);
    for (i = 0; i < len; i++) {
        item->attributes[i].mark = FALSE;
        item->attributes[i].clusterStart = FALSE;
        item->attributes[i].justification = 0;
        item->attributes[i].zeroWidth = FALSE;
        MMDEBUG("    %d: %4x property=%x", i, reordered[i], properties[i]);
    }

    /* now we have the syllable in the right order, and can start running it through open type. */

#ifndef NO_OPENTYPE
    if (openType) {
        hb_uint32 where[32];

        for (i = 0; i < len; ++i) {
            where[i] = ~(PreSubstProperty | BelowSubstProperty
                    | AboveSubstProperty | PostSubstProperty | CligProperty
                    | PositioningProperties);
            if (properties[i] & PreForm)
                where[i] &= ~PreFormProperty;
            if (properties[i] & BelowForm)
                where[i] &= ~BelowFormProperty;
            if (properties[i] & AboveForm)
                where[i] &= ~AboveFormProperty;
            if (properties[i] & PostForm)
                where[i] &= ~PostFormProperty;
        }

        HB_OpenTypeShape(item, where);
        if (!HB_OpenTypePosition(item, availableGlyphs, /*doLogClusters*/FALSE))
            return FALSE;
    } else
#endif
    {
        MMDEBUG("Not using openType");
        HB_HeuristicPosition(item);
    }

    item->attributes[0].clusterStart = TRUE;
    return TRUE;
}
コード例 #14
0
ファイル: roxiemem.hpp プロジェクト: afishbeck/HPCC-Platform
 static void setDestructorFlag(const void *ptr)
 {
     dbgassertex(ptr);
     HeapletBase *h = findBase(ptr);
     h->_setDestructorFlag(ptr);
 }
コード例 #15
0
ファイル: primes.cpp プロジェクト: omartinak/tests
vector<int> findNaive(int count)
{
	return findBase(count, isPrimeNaive);
}
コード例 #16
0
ファイル: primes.cpp プロジェクト: omartinak/tests
vector<int> findRoot(int count)
{
	return findBase(count, isPrimeRoot);
}
コード例 #17
0
ファイル: SaveBlocksPlugin.cpp プロジェクト: KDE/kwave
//***************************************************************************
int Kwave::SaveBlocksPlugin::start(QStringList &params)
{
    qDebug("SaveBlocksPlugin::start()");

    // interprete the parameters
    int result = interpreteParameters(params);
    if (result) return result;

    QString filename = m_url.path();
    QFileInfo file(filename);
    QString path = file.absolutePath();
    QString ext  = file.suffix();
    QString base = findBase(filename, m_pattern);
    QByteArray sep("/");

    // determine the selection settings
    sample_index_t selection_left  = 0;
    sample_index_t selection_right = 0;
    selection(0, &selection_left, &selection_right, false);

    bool selected_something = (selection_left != selection_right);
    bool selected_all = ((selection_left == 0) &&
                         (selection_right+1 >= signalLength()));
    bool enable_selection_only = selected_something && !selected_all;
    bool selection_only = enable_selection_only && m_selection_only;

    if (selection_only) {
	selection(0, &selection_left, &selection_right, true);
    } else {
	selection_left  = 0;
	selection_right = signalLength() - 1;
    }

    // get the index range
    scanBlocksToSave(base, selection_only);
    unsigned int count = m_block_info.count();
    unsigned int first = firstIndex(path, base, ext, m_pattern,
                                    m_numbering_mode, count);

//     qDebug("m_url            = '%s'", m_url.prettyURL().local8Bit().data());
//     qDebug("m_pattern        = '%s'", m_pattern.local8Bit().data());
//     qDebug("m_numbering_mode = %d", (int)m_numbering_mode);
//     qDebug("selection_only   = %d", selection_only);
//     qDebug("indices          = %u...%u (count=%u)", first, first+count-1,count);

    // iterate over all blocks to check for overwritten files and missing dirs
    QStringList  overwritten_files;
    QStringList  missing_dirs;
    for (unsigned int i = first; i < (first + count); i++) {
	QString name = createFileName(base, ext, m_pattern, i, count,
	                              first + count - 1);
	QString display_name = Kwave::Parser::unescape(name);

	// split the name into directory and file name
	name = QString::fromLatin1(QUrl::toPercentEncoding(display_name, sep));
	QUrl url = m_url.adjusted(QUrl::RemoveFilename);
	url.setPath(url.path(QUrl::FullyEncoded) + name, QUrl::StrictMode);

	QString filename = url.path();
	QFileInfo file_info(filename);

	// check for potentially overwritten file
	if (file_info.exists())
	    overwritten_files += Kwave::Parser::unescape(display_name);

	// check for missing subdirectory
	if (!file_info.dir().exists()) {
	    QFileInfo inf(display_name);
	    QString missing_dir = inf.path();
	    if (!missing_dirs.contains(missing_dir))
		missing_dirs += missing_dir;
	}
    }

    // inform about overwritten files
    if (!overwritten_files.isEmpty()) {
	// ask the user for confirmation if he really wants to overwrite...
	if (Kwave::MessageBox::warningYesNo(parentWidget(),
	    _("<html>") +
	    i18n("This would overwrite the following file(s): %1" \
	    "Do you really want to continue?",
	    createDisplayList(overwritten_files, 5)) +
	    _("</html>") ) != KMessageBox::Yes)
	{
	    return -1;
	}
    }

    // handle missing directories
    if (!missing_dirs.isEmpty()) {
	// ask the user if he wants to continue and create the directory
	if (Kwave::MessageBox::warningContinueCancel(parentWidget(),
	    i18n("The following directories do not exist: %1"
	         "Do you want to create them and continue?",
	         createDisplayList(missing_dirs, 5)),
	    QString(),
	    QString(),
	    QString(),
	    _("saveblocks_create_missing_dirs")
	    ) != KMessageBox::Continue)
	{
	    return -1;
	}

	// create all missing directories
	QUrl base_url = m_url.adjusted(QUrl::RemoveFilename);
	foreach (const QString &missing, missing_dirs) {
	    QUrl url(base_url);
	    url.setPath(
		base_url.path(QUrl::FullyEncoded) +
		QString::fromLatin1(QUrl::toPercentEncoding(missing)),
		QUrl::StrictMode
	    );
	    QString path = url.path();
	    QDir dir;
	    if (!dir.mkpath(path))
		qWarning("creating path '%s' failed", DBG(path));
	}
    }
コード例 #18
0
ファイル: SaveBlocksPlugin.cpp プロジェクト: KDE/kwave
//***************************************************************************
QStringList *Kwave::SaveBlocksPlugin::setup(QStringList &previous_params)
{
    // try to interpret the previous parameters
    interpreteParameters(previous_params);

    // create the setup dialog
    sample_index_t selection_left  = 0;
    sample_index_t selection_right = 0;
    selection(0, &selection_left, &selection_right, false);

    // enable the "selection only" checkbox only if there is something
    // selected but not everything
    bool selected_something = (selection_left != selection_right);
    bool selected_all = ((selection_left == 0) &&
                         (selection_right + 1 >= signalLength()));
    bool enable_selection_only = selected_something && !selected_all;

    QString filename = m_url.path();
    QString base = findBase(filename, m_pattern);
    scanBlocksToSave(base, m_selection_only && enable_selection_only);

    QPointer<Kwave::SaveBlocksDialog> dialog =
	new(std::nothrow) Kwave::SaveBlocksDialog(
	    _("kfiledialog:///kwave_save_blocks"),
	    Kwave::CodecManager::encodingFilter(),
	    parentWidget(),
	    QUrl::fromUserInput(signalName()),
	    _("*.wav"),
	    m_pattern,
	    m_numbering_mode,
	    m_selection_only,
	    enable_selection_only
	);
    if (!dialog) return 0;

    // connect the signals/slots from the plugin and the dialog
    connect(dialog, SIGNAL(sigSelectionChanged(QString,
	QString,Kwave::SaveBlocksPlugin::numbering_mode_t,bool)),
	this, SLOT(updateExample(QString,QString,
	Kwave::SaveBlocksPlugin::numbering_mode_t,bool)));
    connect(this, SIGNAL(sigNewExample(QString)),
	dialog, SLOT(setNewExample(QString)));

    dialog->setWindowTitle(i18n("Save Blocks"));
    dialog->emitUpdate();
    if (dialog->exec() != QDialog::Accepted) {
	delete dialog;
	return 0;
    }

    QStringList *list = new QStringList();
    Q_ASSERT(list);
    if (list) {
	// user has pressed "OK"
	QString pattern;

	QUrl url = dialog->selectedUrl();
	if (url.isEmpty()) {
	    delete dialog;
	    return 0;
	}
	QString name = url.path();
	QFileInfo path(name);

	// add the correct extension if necessary
	if (!path.suffix().length()) {
	    QString ext = dialog->selectedExtension();
	    QStringList extensions = ext.split(_(" "));
	    ext = extensions.first();
	    name += ext.mid(1);
	    path = name;
	    url.setPath(name);
	}

	name     = Kwave::Parser::escape(name);
	pattern  = Kwave::Parser::escape(dialog->pattern());
	int mode = static_cast<int>(dialog->numberingMode());
	bool selection_only = (enable_selection_only) ?
	    dialog->selectionOnly() : m_selection_only;

	*list << name;
	*list << pattern;
	*list << QString::number(mode);
	*list << QString::number(selection_only);

	emitCommand(_("plugin:execute(saveblocks,") +
	    name + _(",") + pattern + _(",") +
	    QString::number(mode) + _(",") +
	    QString::number(selection_only) + _(")")
	);
    } else {
	// user pressed "Cancel"
	delete list;
	list = 0;
    }

    if (dialog) delete dialog;
    return list;
}