Psilon
Master of Orion
5929 / 4828 / 634
Регистрация: 10.07.2011
Сообщений: 14,439
|
18.06.2014, 18:32
|
|
C++ | 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
| #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool predicate(char a, char b)
{
bool isA = isalpha(a);
bool isB = isalpha(b);
return isA && !isB;
}
void main(){
setlocale(LC_ALL, "rus");
string s = "agasg ... 19hafsfa ;' asdf";
//cout << "Введите строку" << endl;
//cin >> s;
cout << s << endl;
vector<char> chars(s.begin(), s.end());
std::stable_sort(chars.begin(), chars.end(), predicate);
for (char c : chars)
{
cout << c;
}
} |
|
Добавлено через 2 минуты
чуть менее понятно, но короче:
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void main(){
setlocale(LC_ALL, "rus");
string s = "agasg ... 19hafsfa ;' asdf";
//cout << "Введите строку" << endl;
//cin >> s;
cout << s << endl;
vector<char> chars(s.begin(), s.end());
std::stable_sort(chars.begin(), chars.end(), [](char a, char b){ return isalpha(a) && !isalpha(b); });
for (char c : chars)
{
cout << c;
}
} |
|
0
|