-
Notifications
You must be signed in to change notification settings - Fork 22
/
0026.cpp
38 lines (35 loc) · 837 Bytes
/
0026.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 0026.字符串排序
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<char, int> p1, pair<char, int> p2)
{
if(toupper(p1.first) == toupper(p2.first)) return p1.second < p2.second;
return toupper(p1.first) < toupper(p2.first);
}
int main()
{
string s;
while(getline(cin, s))
{
vector<pair<char, int> > v;
for(int i = 0; i < s.size(); i++)
{
if(!isalpha(s[i])) continue;
v.push_back(make_pair(s[i], i));
}
sort(v.begin(), v.end(), cmp);
for(int i = 0, j = 0; i < s.size(); i++)
{
if (!isalpha(s[i])) {
cout << s[i];
}else {
cout << v[j++].first;
}
}
cout << endl;
}
return 0;
}