STL 笔记
来源:互联网 发布:js计算一年中的某天 编辑:程序博客网 时间:2024/06/06 05:20
map<const string,int> wordmap;bool NotNeed(char c){ return ispunct(c);}bool NotDigtilAndNotDouble(const std::pair<const string, int>& word){ const char* p = word.first.c_str(); while(*p!='\0') { if (*p >='0' && *p <='9') { return true; } p++; } if (word.second>1) { return true; } return false;}vector< pair<string, int> > vecWords;list<pair<string, int> > lstWords;template <typename T1,typename T2 = int>struct comp{ comp(const T1& s): _s(s){} bool operator() (const std::pair< T1, T2>& p) { return (p.first == _s); } T1 _s;};struct NoMore{ bool operator()(const std::pair<std::string, int>&p) { if (p.second>1) { return true; } else { return false; } }};bool IsDelete(const std::pair<std::string, int>&p){ return p.second>1;}bool is_digits(const std::pair<std::string, int>&p){ return p.first.find_first_not_of("0123456789") == std::string::npos;}void main(){ char* str = "start program this is thread id = 2323, this is my first test (error code = 999) kjhkjh 2000-01-01 00:00:00"; char* expert = "start program this is thread id = %d, this is my first test (error code = %d) kjhkjh"; string s1 = str; s1.erase(remove_if(s1.begin(),s1.end(),NotNeed),s1.end()); string s2 = str; replace_if(s2.begin(),s2.end(),NotNeed,' '); string word; stringstream strstream(s2); while(strstream>>word) { wordmap[ word ]++; vector< pair<string, int> >::iterator it = find_if(vecWords.begin(),vecWords.end(),comp<string>(word)); if (it != vecWords.end()) { it->second++; } else { vecWords.push_back(std::make_pair(word,1)); } list<pair<string, int> >::iterator lstIt = find_if(lstWords.begin(),lstWords.end(),comp<string>(word)); if (lstIt != lstWords.end()) { lstIt->second++; } else { lstWords.push_back(std::make_pair(word,1)); } } vector< pair<string, int> >::iterator it = vecWords.begin(); vecWords.erase(remove_if(vecWords.begin(),vecWords.end(),NoMore())); lstWords.remove_if(IsDelete); lstWords.remove_if(is_digits); map<const string,int>::iterator itor = wordmap.begin(); while( (itor = find_if(itor,wordmap.end(),NotDigtilAndNotDouble)) != wordmap.end() ) { wordmap.erase(itor++); }}
2.
bool compare(char str1, char str2){ string s1 = "([{"; string s2 = ")]}"; if (s1.find(str1) == s2.find(str2)) { return true; } else { return false; }}bool charChecking(string s){ bool balanced = true; stack<char> szStack; size_t index = 0; while(index < s.size() && balanced) { char symbol = s[index]; if (symbol == '(' || symbol == '[' || symbol == '{') { szStack.push(symbol); } else { if (szStack.empty()) { balanced = false; } else { char top = stack.pop(); if (!compare(top , symbol)) { balanced = false; } } } index += 1; } if (balanced && szStack.empty()) { return true; } else { return false; }}
0 0
- stl笔记
- STL笔记
- STL笔记
- STL 笔记
- stl笔记
- STL笔记
- 【笔记】STL
- STL学习笔记-->初识STL
- STL学习笔记--初识STL
- STL之学习笔记
- stl学习笔记1
- stl学习笔记2
- stl学习笔记3
- stl学习笔记4
- stl学习笔记5
- stl学习笔记6
- stl学习笔记7
- stl 学习笔记 8
- 字符串转置
- PHP源码分析之HashTable(2)
- js 复制网页内容,兼容各浏览器
- 命令行输入命令错误解决方法
- 黑马程序员 java高新技术- 类加载器和动态代理
- STL 笔记
- 1515:打印1到最大的N位数 @jobdu
- 黑马程序员 jdk1.5新特性和枚举。
- Boost 之circular_buffer
- 1516:调整数组顺序使奇数位于偶数前面 @jobdu
- timer
- 1517:链表中倒数第k个结点 @jobdu
- nginx实现310重定向
- 删除mssql企业管理器中的服务器注册名