题解 | #图片整理#

图片整理

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")

全部评论

相关推荐

05-16 21:54
已编辑
门头沟学院 前端工程师
蓝曦111:我也是25届,这是第二次被裁了,毕业没到一年就失业两次,两次都是公司问题。第一家才转正一个月,跟我说公司拿不到项目结款没办法,赔了一个月;第二个公司连工资都发不出来了,赔偿更别想了,我算是认命了,这条路也不知道能走多远走多久,不过生活还是要继续的,走一步看一步吧
当你面对裁员会如何?
点赞 评论 收藏
分享
许愿一个offer_...:不是啊,这个只代表你的面试官提交了你的面评,面试是否通过还是要看官网状态呢
腾讯2025实习生招聘
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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