sungmin2ee   9달 전

#include <iostream>

#include <vector>

#include <cstring>

#include <algorithm>

#include <list>

#include <math.h>

using namespace std;

int main() {

int n;

cin >> n;

vector <string>arr;

for (int i = 0; i < n; i++) {

string s = "";

cin >> s;

arr.push_back(s);

}

sort(arr.begin(), arr.end());

vector<string>::iterator iter = arr.begin();

for (iter; iter != arr.end();) {

if (iter == arr.end() - 1)

break;

if (*iter == *(iter +1)) {

iter = arr.erase(iter);

}

else {

iter++;

}

}

for (int i = 0; i < arr.size()-1; i++) {

for (int j = i+1; j < arr.size(); j++) {

if (arr[i].length() > arr[j].length()) {

swap(arr[i], arr[j]);

}

}

}

for (int i = 0; i < arr.size(); i++) {

cout << arr[i] << endl;

}

}

zenith82114   9달 전

이 방법이 맞으려면 두 번째 정렬이 안정(stable)한 정렬이어야 합니다. 버블 정렬은 안정하지 않습니다.

버블 정렬은 안정하지만, 현재 구현이 틀렸습니다. 올바르게 고치면 통과됩니다.

댓글을 작성하려면 로그인해야 합니다.