摘要: 1 /* 2 编写程序统计并输出所读入的单词出现的次数 3 4 */ 5 /* 6 //代码一:---用map索引实现惊人的简练 7 #include 8 #include 9 10 using namespace std;11 12 int main()13 {14 map word_cnt;15 string word;16 while(cin >> word)17 {18 ++word_cnt[word];//如果查找键值word不存在,那么map中就会插入键值为word的新元素,同时用值初始化或默认构造函数初始化19 ... 阅读全文
posted @ 2013-09-10 10:08 可笑痴狂 阅读(475) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 4 using namespace std; 5 6 void ptrswap(int *&v1, int *&v2)//交换指针所指的地址 7 { 8 cout << endl; 9 cout << *v1 << "\t\t" << *v2 << endl;10 int *tmp = v1;11 v1 = v2;12 v2 = tmp;13 cout << *v1 << "\t\t" << *v 阅读全文
posted @ 2013-09-10 10:04 可笑痴狂 阅读(283) 评论(0) 推荐(0)
摘要: 1 #include 2 using namespace std; 3 4 int main() 5 { 6 int ival; 7 while(cin >> ival, !cin.eof()) 8 { 9 if(cin.bad())10 throw runtime_error("IO stream corrupted");11 if(cin.fail())12 {13 cerr 2 3 using namespace std; 4 5 istream & fun... 阅读全文
posted @ 2013-09-10 10:03 可笑痴狂 阅读(405) 评论(0) 推荐(0)
摘要: #include #include #include using namespace std;int main(){ set setInt; vector ivec; for(vector::size_type i = 0; i != 11; ++i) ivec.push_back(i); setInt.insert(ivec.begin(), ivec.end()); setInt.insert(11); set::iterator itor1 = setInt.find(9);// 这个也对,为什么const类型的键值可以用非const的... 阅读全文
posted @ 2013-09-10 10:01 可笑痴狂 阅读(296) 评论(0) 推荐(0)
摘要: 1 /* 2 编写程序读入一些列string和int型数据,将每一组存储在一个pair对象中, 3 然后将这些pair对象存储在vector容器里。 4 */ 5 6 #include 7 #include 8 #include //pair在里边定义 9 10 using namespace std;11 12 int main()13 {14 vector > vp;15 string key;16 int val;17 while(cin >> key >> val)18 {19 //vp.push_b... 阅读全文
posted @ 2013-09-10 10:00 可笑痴狂 阅读(421) 评论(0) 推荐(0)
摘要: 1 /* 2 multimap中的三种遍历方法 3 multimap中如果没有查找到相应元素,则返回的迭代器是依据该元素的排列顺序该键应该插入的位置 4 如果找不到,则方法一和方法二返回的两个迭代器应该相等 5 */ 6 #include 7 #include 8 #include 9 #include 10 11 using namespace std;12 13 int main()14 {15 multimap mulMap;16 mulMap.insert(make_pair("鲁迅", "朝花夕拾"));17 mulMap.in... 阅读全文
posted @ 2013-09-10 09:57 可笑痴狂 阅读(19147) 评论(1) 推荐(3)