| #include <iostream> |
| #include <string> |
| #include <map> |
| #include <vector> |
| #include <algorithm> |
| --------------------------------------------------------------------- |
| typedef std::string T_str; |
| typedef std::vector<T_str> T_vec; |
| typedef std::map<T_str, int> T_map; |
| typedef T_map::iterator T_map_it; |
| typedef std::pair<T_str, int> T_pair; |
| --------------------------------------------------------------------- |
| int split_str_to_vec(const T_str , const T_str, T_vec & ); |
| int main() |
| { |
| T_str str("Hi Hello world Hello Hi, Hi Hi Hello"); |
| T_map set; |
| T_vec v; |
| split_str_to_vec(str, " tn,.-", v); |
| std::for_each(v.begin(), v.end(), & (T_str str) { ++setstr; }); |
| T_map_it it = std::max_element(set.begin(), set.end(), ( T_pair (a), T_pair (b)) { return a.second < b.second; }); |
| std::cout << (it != set.end() ? it->first : "Error" ) << std::endl; |
| return 0; |
| } |
| int split_str_to_vec(const T_str s, const T_str DELIM, T_vec &v) |
| { |
| size_t l, r; |
| for ( l = s.find_first_not_of(DELIM), r = s.find_first_of(DELIM, l) ; |
| l != std::string::npos ; l = s.find_first_not_of(DELIM, r), r = s.find_first_of(DELIM, l) ) |
| v.push_back(s.substr(l, r - l)); |
| return v.size(); |
| } |
Комментарии