⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 high_scores.cpp

📁 the source of dev_c++ most of them for game development
💻 CPP
字号:
// High Scores
// Demonstrates algorithms

#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
    vector<int>::const_iterator iter;

    cout << "Creating a list of scores.";
    vector<int> scores;
    scores.push_back(1500);
    scores.push_back(3500);
    scores.push_back(7500);

    cout << "\nHigh Scores:\n";
    for (iter = scores.begin(); iter != scores.end(); ++iter)
        cout << *iter << endl;

    cout << "\nRandomizing scores.";
    srand(time(0));
    random_shuffle(scores.begin(), scores.end());
    cout << "\nHigh Scores:\n";
    for (iter = scores.begin(); iter != scores.end(); ++iter)
        cout << *iter << endl;

    cout << "\nSorting scores.";
    sort(scores.begin(), scores.end());
    cout << "\nHigh Scores:\n";
    for (iter = scores.begin(); iter != scores.end(); ++iter)
        cout << *iter << endl;

    cout << "\nCreating another list of scores." ;
    vector<int> moreScores;
    moreScores.push_back(2000);
    moreScores.push_back(4000);
    moreScores.push_back(8000);

    cout << "\nMore High Scores:\n";
    for (iter = moreScores.begin(); iter != moreScores.end(); ++iter)
        cout << *iter << endl;

    cout << "\nMerging both lists.";
    vector<int> allScores(6);  //need container big enough to hold results
    merge(scores.begin(), scores.end(),
          moreScores.begin(), moreScores.end(),
          allScores.begin());

    cout << "\nAll High Scores:\n";
    for (iter = allScores.begin(); iter != allScores.end(); ++iter)
        cout << *iter << endl;

 return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -