관리 메뉴

사적공간

선택정렬 본문

KNOU_CS/C++

선택정렬

2sac 2024. 10. 30. 13:10
#include <iostream>
#include <cstring>
using namespace std;
    
void sort(int x[]) {
    int temp;
    for (int i = 0; i < 6; i++) {
        for (int k = i; k < 6; k++) {
            if (x[i] < x[k]) {
                temp = x[i]; x[i] = x[k]; x[k] = temp; 
            }
        }
    }
    cout << x[0];
    cout << x[1];
    cout << x[2];
    cout << x[3];
    cout << x[4];
    cout << x[5];
}


int main() {
    int arr[6];
    for (int i = 0; i < 6; i++) {
        cin >> arr[i];
    }
    
    sort(arr);

    return 0;
}

 

 

#include <iostream>
#include <cstring>
using namespace std;


int main() {
    char arr[100];
    cin >> arr; 

    char temp; 
    int len = strlen(arr); 
    for (int i = 0; i < len; i++) {
        for (int k = i+1; k < len; k++) {
            if (arr[i] > arr[k]) {
                temp = arr[i];
                arr[i] = arr[k];
                arr[k] = temp; 
            }
        }
    }
    int j = 0;
    while (1) {
        if (j == len) break;
        cout << arr[j]; 
        j++; 
    }


    return 0;
}