1. 程式人生 > >ex10_4字符串中字符排序

ex10_4字符串中字符排序

class copyright reserve pre copy 實現 include 自己 out

//
//  main.cpp
//  ex10_4
//
//  Created by a007 on 17/12/1.
//  Copyright ? 2017年 a007. All rights reserved.
//

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

int main(int argc, const char * argv[]) {
    string s;
    cout << "Enter a string s: ";
    cin >> s;
    
    sort(begin(s), end(s));
    cout << s << endl;
    return 0;
}

這段程序偷懶用了標準算法庫函數sort,不過最好還是自己手工實現一遍,加深理解。

ex10_4字符串中字符排序