C/C++[codeup 1927]字符串内排序

题目描述1927字符串内排序

输入一个字符串,长度小于等于200,然后将输出按字符顺序升序排序后的字符串。

输入
测试数据有多组,输入字符串。

输出
对于每组输入,输出处理后的结果。

样例输入
tianqin
样例输出
aiinnqt
提示
注意输入的字符串中可能有空格
使用fgets()遇到了迷之错误

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
    char str[201] = {};
    while(gets(str) != NULL) {
        int l = strlen(str);
        sort(str, str+l);
        printf("%s\n",str);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/u014281392/article/details/80804939
今日推荐