题解 | #图片整理#

图片整理

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;
    }
}
全部评论

相关推荐

牛客48826091...:哥们胸肌挺好看
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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