int maxCount(TreeNode* treeNode){ if (treeNode == NULL) return -1; int left = maxCount(treeNode->left); int right = maxCount(treeNode->right); // Find max of counters if (((WordCount*)treeNode->value)->count >= left && ((WordCount*)treeNode->value)->count >= right) return ((WordCount*)treeNode->value)->count; else if (left >= ((WordCount*)treeNode->value)->count && left >= right) return left; else return right; }
int main(){ int n; scanf("%d", &n); std::vector<int64_t> a(n); for(int p = 0; p < n; p++){scanf("%ld", &a[p]);} sort(a.begin(), a.end()); double mean(0), sum(0), median(0); int64_t mode(0), count(0), maxCount(0); if(n % 2){median = a[n / 2];} else{median = (a[n / 2 - 1] + a[n / 2]) / 2.0;} mean = mode = a[0]; count = 1; for(int p = 1; p < n; p++){ mean += a[p]; if(a[p - 1] == a[p]){ ++count; if(count > maxCount){maxCount = count; mode = a[p];} } else{count = 1;} } mean /= 1.0 * n; printf("%.1lf\n%.1lf\n%lld\n", mean, median, mode); return 0; }
void KHistoryComboBox::setHistoryItems( const QStringList &items, bool setCompletionList ) { QStringList insertingItems = items; KComboBox::clear(); // limit to maxCount() const int itemCount = insertingItems.count(); const int toRemove = itemCount - maxCount(); if (toRemove >= itemCount) { insertingItems.clear(); } else { for (int i = 0; i < toRemove; ++i) insertingItems.pop_front(); } insertItems( insertingItems ); if ( setCompletionList && useCompletion() ) { // we don't have any weighting information here ;( KCompletion *comp = completionObject(); comp->setOrder( KCompletion::Insertion ); comp->setItems( insertingItems ); comp->setOrder( KCompletion::Weighted ); } clearEditText(); }
void QRecentFilesMenu::addRecentFile(const QString &fileName) { m_files.removeAll(fileName); m_files.prepend(fileName); while (m_files.size() > maxCount()) m_files.removeLast(); updateRecentFileActions(); }
QString ContainerContent::dump() { QString result = "Content of array:\n"; result += QString( "Count: %1; MaxCount: %2\n" ).arg( count() ).arg( maxCount() ); size_t count = this->count(); for ( size_t i = 2; i < 2 + count; ++i ) { result += QString( "At %1: 0x%2\n" ).arg( i - 2 ).arg( reinterpret_cast<size_t>( content[i] ), 0, 16 ); } return result; }
void pCheckComboBox::insertSeparator( int index ) { const int itemCount = count(); index = qBound( 0, index, itemCount ); if ( index >= maxCount() ) { return; } insertItem( index, QIcon(), QString::null ); pCheckComboBoxDelegate::setSeparator( model(), modelIndex( index ), true ); }
void KHistoryComboBox::addToHistory( const QString& item ) { if ( item.isEmpty() || (count() > 0 && item == itemText(0) )) { return; } bool wasCurrent = false; // remove all existing items before adding if ( !duplicatesEnabled() ) { int i = 0; int itemCount = count(); while ( i < itemCount ) { if ( itemText( i ) == item ) { if ( !wasCurrent ) wasCurrent = ( i == currentIndex() ); removeItem( i ); --itemCount; } else { ++i; } } } // now add the item if ( d->myPixProvider ) insertItem( 0, d->myPixProvider->pixmapFor(item, iconSize().height()), item); else insertItem( 0, item ); if ( wasCurrent ) setCurrentIndex( 0 ); const bool useComp = useCompletion(); const int last = count() - 1; // last valid index const int mc = maxCount(); const int stopAt = qMax(mc, 0); for (int rmIndex = last; rmIndex >= stopAt; --rmIndex) { // remove the last item, as long as we are longer than maxCount() // remove the removed item from the completionObject if it isn't // anymore available at all in the combobox. const QString rmItem = itemText( rmIndex ); removeItem( rmIndex ); if ( useComp && !contains( rmItem ) ) completionObject()->removeItem( rmItem ); } if ( useComp ) completionObject()->addItem( item ); }
void VBoxDbgConsoleInput::returnPressed() { Assert(m_hGUIThread == RTThreadNativeSelf()); QString strCommand = currentText(); /** @todo trim whitespace? */ if (strCommand.isEmpty()) return; /* deal with the current command. */ emit commandSubmitted(strCommand); /* * Add current command to history. */ bool fNeedsAppending = true; /* invariant: empty line at the end */ int iLastItem = count() - 1; Assert(itemText(iLastItem).isEmpty()); /* have previous command? check duplicate. */ if (iLastItem > 0) { const QString strPrevCommand(itemText(iLastItem - 1)); if (strCommand == strPrevCommand) fNeedsAppending = false; } if (fNeedsAppending) { /* history full? drop the oldest command. */ if (count() == maxCount()) { removeItem(0); --iLastItem; } /* insert before the empty line. */ insertItem(iLastItem, strCommand); } /* invariant: empty line at the end */ int iNewLastItem = count() - 1; Assert(itemText(iNewLastItem).isEmpty()); /* select empty line to present "new" command line to the user */ setCurrentIndex(iNewLastItem); }
QDebug ListAppender::debug(QDebug &rDebug) const { rDebug.nospace() << "ListAppender(" << "name:" << name() << " " << "count:" << list().count() << " " << "filter:" << firstFilter() << " " << "isactive:" << isActive() << " " << "isclosed:" << isClosed() << " " << "maxcount:" << maxCount() << " " << "referencecount:" << referenceCount() << " " << "threshold:" << threshold().toString() << ")"; return rDebug.space(); }
void KHistoryComboBox::slotSimulateActivated( const QString& text ) { /* With the insertion policy NoInsert, which we use by default, Qt doesn't emit activated on typed text if the item is not already there, which is perhaps reasonable. Generate the signal ourselves if that's the case. */ if ((insertPolicy() == NoInsert && findText(text, Qt::MatchFixedString|Qt::MatchCaseSensitive) == -1)) { emit activated(text); } /* Qt also doesn't emit it if the box is full, and policy is not InsertAtCurrent */ else if (insertPolicy() != InsertAtCurrent && count() >= maxCount()) { emit activated(text); } }
// called right before a new (different!) temporary item will be set. So we // insert an item that was marked permanent properly at position 1. void KonqCombo::applyPermanent() { if ( m_permanent && !temporaryItem().isEmpty() ) { // Remove as many items as needed to honor maxCount() int index = count(); while ( count() >= maxCount() ) removeItem( --index ); QString item = temporaryItem(); insertItem( KonqPixmapProvider::self()->pixmapFor( item ), item, 1, titleOfURL( item ) ); //kDebug() << url; // Remove all duplicates starting from index = 2 removeDuplicates( 2 ); m_permanent = false; } }
int main(){ FILE *fp; char c, file_name[sizeof(char)], oneword[sizeof(char)]; TreeBase* tree = new_base(compareWords, freeNode, printWordCount); printf("Enter the name of file you wish to see\n> "); scanf("%s", file_name); fp = fopen(file_name,"r"); // Check error if (fp == NULL){ perror("Error while opening the file.\n"); exit(EXIT_FAILURE); } int i = 0; // Read the whole file while ((c = fgetc(fp)) != EOF){ // get charachters from the file until the end // if in is not alphanumeric if (!((c >= 'a' && c <= 'z') || ((c >= 'A' && c <= 'Z') || c == '\0'|| c == '\''))){ oneword[i] = '\0'; // end of the string if (strlen(oneword) > 0){ // Word cannot be empty WordCount* wc = new_word(oneword); insert(tree, wc); i = 0; } } else{ c = tolower(c); // convert all letters in the word to lowercase oneword[i] = c; i++; } } fclose(fp); printTree(tree); int max = maxCount(tree->base); // find most common word counter printf("The most common word \"%s\" occurs %d times\n", mostUsedWord(tree->base, max), max); printf("Total number of characters in all words: %d\n", sumWordLength(tree->base)); printf("Average word length: %d\n", averageWordLength(tree->base)); printf("Total number of words: %d", totalNumOfWords(tree->base)); freeTree(tree); }
void QRecentFilesMenu::updateRecentFileActions() { int numRecentFiles = qMin(m_files.size(), maxCount()); clear(); for (int i = 0; i < numRecentFiles; ++i) { QString strippedName = QFileInfo(m_files[i]).fileName(); QString text = m_format; text.replace(QLatin1String("%d"), QString::number(i + 1)); text.replace(QLatin1String("%s"), strippedName); QAction* recentFileAct = addAction(text); recentFileAct->setData(m_files[i]); } addSeparator(); addAction(QIcon(":/images/cancel.png"),tr("Clear Menu"), this, SLOT(clearMenu())); setEnabled(numRecentFiles > 0); }
int QComboBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 24) qt_static_metacall(this, _c, _id, _a); _id -= 24; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = isEditable(); break; case 1: *reinterpret_cast< int*>(_v) = count(); break; case 2: *reinterpret_cast< QString*>(_v) = currentText(); break; case 3: *reinterpret_cast< int*>(_v) = currentIndex(); break; case 4: *reinterpret_cast< int*>(_v) = maxVisibleItems(); break; case 5: *reinterpret_cast< int*>(_v) = maxCount(); break; case 6: *reinterpret_cast< InsertPolicy*>(_v) = insertPolicy(); break; case 7: *reinterpret_cast< SizeAdjustPolicy*>(_v) = sizeAdjustPolicy(); break; case 8: *reinterpret_cast< int*>(_v) = minimumContentsLength(); break; case 9: *reinterpret_cast< QSize*>(_v) = iconSize(); break; case 10: *reinterpret_cast< bool*>(_v) = autoCompletion(); break; case 11: *reinterpret_cast< Qt::CaseSensitivity*>(_v) = autoCompletionCaseSensitivity(); break; case 12: *reinterpret_cast< bool*>(_v) = duplicatesEnabled(); break; case 13: *reinterpret_cast< bool*>(_v) = hasFrame(); break; case 14: *reinterpret_cast< int*>(_v) = modelColumn(); break; } _id -= 15; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setEditable(*reinterpret_cast< bool*>(_v)); break; case 3: setCurrentIndex(*reinterpret_cast< int*>(_v)); break; case 4: setMaxVisibleItems(*reinterpret_cast< int*>(_v)); break; case 5: setMaxCount(*reinterpret_cast< int*>(_v)); break; case 6: setInsertPolicy(*reinterpret_cast< InsertPolicy*>(_v)); break; case 7: setSizeAdjustPolicy(*reinterpret_cast< SizeAdjustPolicy*>(_v)); break; case 8: setMinimumContentsLength(*reinterpret_cast< int*>(_v)); break; case 9: setIconSize(*reinterpret_cast< QSize*>(_v)); break; case 10: setAutoCompletion(*reinterpret_cast< bool*>(_v)); break; case 11: setAutoCompletionCaseSensitivity(*reinterpret_cast< Qt::CaseSensitivity*>(_v)); break; case 12: setDuplicatesEnabled(*reinterpret_cast< bool*>(_v)); break; case 13: setFrame(*reinterpret_cast< bool*>(_v)); break; case 14: setModelColumn(*reinterpret_cast< int*>(_v)); break; } _id -= 15; } else if (_c == QMetaObject::ResetProperty) { _id -= 15; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 15; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 15; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 15; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 15; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 15; } #endif // QT_NO_PROPERTIES return _id; }