描述 | |
---|---|
知识点 | 字符串,排序 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | |
输出 | |
样例输入 | A Famous Saying: Much Ado About Nothing (2012/8). |
样例输出 | A aaAAbc dFgghh: iimM nNn oooos Sttuuuy (2012/8). |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void SplitAlpha(string src, string &dst)
{
for (int i = 0; i < src.length(); i++)
{
if (isalpha(src[i]))
{
dst.push_back(src[i]);
}
}
}
void Sort(string &str)
{
for (int i = 1; i < str.length(); i++)
{
char tmp = str[i];
int j = i - 1;
for (j; j >= 0; j--)
{
if (toupper(tmp) < toupper(str[j]))
{
str[j + 1] = str[j];
}
else
break;
}
str[j + 1] = tmp;
}
}
int main()
{
string src, dst;
getline(cin, src);
SplitAlpha(src, dst);
Sort(dst);
int i = 0, j = 0;
for (i, j; i < src.length() && j < dst.length(); i++)
{
if (isalpha(src[i]))
{
src[i] = dst[j];
j++;
}
}
cout << src;
return 0;
}