题解 | #图片整理#

图片整理

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

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

/*
思路:先数字、大写字母、小写字母分离出来,再分别进行排序,最后进行合并
*/
string sortChar(string strIn)
{
    string numStr, capitalStr, lowercaseStr;
    for(int i = 0; i < strIn.length(); i++) {
        if(strIn[i] >= '0' && strIn[i] <= '9') {
            numStr += strIn[i];
        } else if(strIn[i] >= 'A' && strIn[i] <= 'Z') {
            capitalStr += strIn[i];
        } else if(strIn[i] >= 'a' && strIn[i] <= 'z') {
            lowercaseStr += strIn[i];
        } 
    }
    
    sort(numStr.begin(), numStr.end());
    sort(capitalStr.begin(), capitalStr.end());
    sort(lowercaseStr.begin(), lowercaseStr.end());
    
   return numStr + capitalStr + lowercaseStr;
}

int main()
{
    string strIn;
    while(cin>>strIn) {
        cout<<sortChar(strIn)<<endl;
    }
}
全部评论

相关推荐

10-13 22:56
门头沟学院 C++
rt,鼠鼠的浪潮网签明天过期,鼠鼠是山东人,好像自己也能接受。之前的面试大厂基本挂干净了,剩下小米二面后在泡,问了下面试官没有挂,但要泡。还有海信似乎也通过了,不过在深圳,鼠鼠也不是很想去。其它还有一些公司应该陆陆续续还有一些面试,现在有些纠结是直接签了还是再等再面呢?大佬们能不能给鼠鼠提一些意见,万分感谢!!!
牛客78696106...:浪潮可不是开摆,当初我还是开发的时候我组长跟我说他们组有段时间天天1,2点走,早上5点就来,全组肝出来心肌炎,浪潮挣钱省立花可不是说说,当然也看部门,但是浪潮普遍就那dio样,而且你算下时薪就知道不高,没事也是9点半走,不然算你旷工
投递小米集团等公司10个岗位
点赞 评论 收藏
分享
09-28 22:01
已编辑
广西科技大学 IT技术支持
合适才能收到offe...:找桌面运维?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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