int main() { const int SIZE = 20; int arr[SIZE] = { 2, 1, 3, 3, 6, 6, 5, 5, 5, 8, 7, 4, 1, 1, 1, 1, 9, 6, 5, 4 }; cout << "Array is:" << endl; for (int i =0; i<SIZE;i++) { cout << arr[i] << " "; } Ims greaterSub; greaterSub.insert(arr, arr + SIZE); Ims::iterator it; int sum = 0; for (it = greaterSub.begin(); it != greaterSub.end(); it++) { sum += *it; } int avg = sum / greaterSub.size(); it = greaterSub.begin(); unsigned int max = 0; int numb; while (it != greaterSub.end()) { if (*it > avg) { if (max < greaterSub.count(*it)) { max = greaterSub.count(*it); numb = *it; } } it = greaterSub.upper_bound(*it); } cout << "\nAverrage is: " << avg << endl; cout << "The longest subsequence of greater values in array is:\n"; cout << numb << " -> " << max << " times." << endl; return 0; }
void MainFrame::AddFile (wxString path) { Ims *ims = new Ims(); ims->Open(path); int index = m_playList->GetItemCount(); // full path long item = m_playList->InsertItem(index, path); // icon m_playList->SetItem(index, 1, wxT("P"), 0); // file wxFileName file(path); m_playList->SetItem(index, 2, file.GetFullName()); // title m_playList->SetItem(index, 3, ims->GetTitle()); // duration long du = ims->GetDuration(); int m = (du%3600)/60; int s = (du%3600)%60; m_playList->SetItem(index, 4, wxString::Format(wxT("%02d:%02d"), m, s)); // Singer wxFileName issFile(path); issFile.SetExt(wxT("iss")); Iss *iss = new Iss(); if ( iss->Open(issFile.GetFullPath()) == true ) { m_playList->SetItem(index, 5, iss->GetSinger()); } delete iss; // total tick //long ticks = ims->GetTotalTick(); //m_playList->SetItem(index, 5, wxString::Format(wxT("%d"), ticks)); delete ims; }
int main() { cout << "Enter number of times: "; unsigned int n; cin >> n; const int SIZE = 20; int a[SIZE] = { 4, 2, 2, 5, 2, 3, 2, 3, 1, 5, 6,5,3,5,7,9,3,1,7,6}; Ims intMultiset; intMultiset.insert(a, a + SIZE); ostream_iterator<int> output(cout, " "); copy(intMultiset.begin(), intMultiset.end(), output); cout << endl; Ims::iterator it; it = intMultiset.begin(); while (it != intMultiset.end()) { if (intMultiset.count(*it) == n) { intMultiset.erase(intMultiset.lower_bound(*it), intMultiset.upper_bound(*it)); } else { it = intMultiset.upper_bound(*it); } } copy(intMultiset.begin(), intMultiset.end(), output); return 0; }