Skip to content

Instantly share code, notes, and snippets.

@dicenull
Created July 30, 2019 12:41
Show Gist options
  • Save dicenull/98d4dde5000d810638f9308ba109c8e3 to your computer and use it in GitHub Desktop.
Save dicenull/98d4dde5000d810638f9308ba109c8e3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> arr(N);
for (int i = 0; i < N; i++)
{
cin >> arr[i];
}
// スターリンソート
int idx = 0;
while (idx < arr.size() - 1)
{
if (arr[idx] > arr[idx + 1])
{
// 小さいほうを粛清
cout << "粛清!!!: " << arr[idx + 1] << endl;
arr.erase(arr.begin() + idx + 1);
idx--;
}
idx++;
}
// ソート結果を出力
for (int i = 0; i < arr.size(); i++)
{
if (i > 0)
{
cout << " ";
}
cout << arr[i];
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment