题解 | #图片整理#

图片整理

https://www.nowcoder.com/practice/2de4127fda5e46858aa85d254af43941

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

int main() {
    string str;
    getline(cin,str);
    for(int i=0;i<str.size();++i){
        for(int j=1;j<str.size()-i;++j){
            if(str[j-1]>str[j]){
                char t=str[j-1];
                str[j-1]=str[j];
                str[j]=t;
            }
        }
    }
    cout << str;
}
// 64 位输出请用 printf("%lld")

#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void quick_sort(string& str,int begin,int end){
    if(begin>=end)
        return;
    char tmp=str[begin];
    int i=begin;
    int j=end;
    while(i<j){
        while(i<j&&str[j]>=tmp)
            --j;
        while (i<j&&str[i]<=tmp) {
            ++i;
        }
        if(i<j){
            char t=str[i];
            str[i]=str[j];
            str[j]=t;
        }
    }
    str[begin]=str[i];
    str[i]=tmp;
    quick_sort(str,begin,i-1);
    quick_sort(str, i+1,end);
}

int main() {
    string str;
    getline(cin,str);
    quick_sort(str,0,str.size()-1);
    cout << str;
}
// 64 位输出请用 printf("%lld")

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

int main() {
    string str;
    getline(cin,str);
    sort(str.begin(),str.end());
    cout << str;
}
// 64 位输出请用 printf("%lld")

#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 设置数组保存每个符号出现次数
int main() {
    string str;
    getline(cin,str);
    vector<int> table(123,0);
    for(char ch:str){
        table[(int)ch]++;
    }
    for(int i=0;i<123;++i){
        while(table[i]){
            cout << char(i);
            table[i]--;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

今年读完研的我无房无车无对象,月入还没有过万&nbsp;看到他在朋友圈晒房产证,感叹自己白读了这么多年书
梦想是成为七海千秋:那咋了,双9毕业的现在还没存款呢(因为没念完),高中毕业的去直播带货月入几百万也是完全有可能的,退一万步讲,有些人刚出生父母就给买车买房了,上哪说理去,哪怕是同一个起点也会有截然不同的走向,过好自己的生活就完事了。
点赞 评论 收藏
分享
不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
真烦好烦真烦:牛友太有实力了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务