Hdu 2072 单词数
2012-12-20 19:53
441 查看
用来练习库函数的使用,第一段代码练习遍历,第二段练习删除。
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <map> #include <algorithm> using namespace std; map<string, int> Map; map<string, int>::iterator it; char str[1010]; void init() { Map.clear(); } int main() { while(gets(str) && strcmp(str, "#")) { init(); char *p = strtok(str, " "); while(p != NULL) { Map[p]++; p = strtok(NULL, " "); } int count = 0; for(it = Map.begin(); it != Map.end(); it++) if(it->second) { count++; } printf("%d\n", count); } return 0; }
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <map> #include <algorithm> using namespace std; map<string, int> Map; map<string, int>::iterator it; char str[1010]; void init() { Map.clear(); } int main() { while(gets(str) && strcmp(str, "#")) { init(); char *p = strtok(str, " "); while(p != NULL) { Map[p]++; p = strtok(NULL, " "); } int count = 0; for(it = Map.begin(); it != Map.end(); it++) if(it->first == "a") { Map.erase(it); } for(it = Map.begin(); it != Map.end(); it++) cout<<it->first<<endl; } return 0; }
相关文章推荐
- HDU 2072 单词数(set)
- hdu 2072 : 单词数 (水)
- hdu 2072 单词数
- HDU 2072 单词数(字符串处理)
- hdu 题目2072 单词数 (字典树)
- hdu2072(不同单词数)
- HDU 2072 单词数(set)
- HDU 2072.单词数【STL的优势以及字符串流的使用】【8月4】
- hdu 2072 单词数 - c++IO流 + set容器
- hdu2072-单词数 字典树、STL
- hdu-2072-单词数
- hdu 2072 单词数统计 sscanf() 函数
- HDU2072 单词数
- hdu 2072 题目 单词数 (C,C++,Java)
- hdu 2072-单词数
- hdu2072—单词数(set)
- HDU 2072 单词数
- HDU 2072 单词数【STL】
- HDU_2072单词数
- hdu 2072 单词数