-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaid.cpp
51 lines (43 loc) · 1.01 KB
/
aid.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
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
class AlphaNumericPredicate {
public:
bool operator() (char c)
{
return (isalnum(c));
}
};
template<typename InputIterator, typename OutputIterator, typename UnaryPredicate>
OutputIterator filter(InputIterator first, InputIterator last,
OutputIterator result,
UnaryPredicate predicate)
{
while (first!=last) {
if(predicate(*first)){
*result++ = *first++;
}
else
*first++;
}
return result;
}
std::string filter_string(std::string source)
{
source.erase(filter(std::begin(source), std::end(source),
std::begin(source),
AlphaNumericPredicate{}),
std::end(source));
return source;
}
int main()
{
while (!std::cin.eof())
{
std::string source;
std::getline(std::cin, source);
std::cout << filter_string(source) << std::endl;
}
return 0;
}