您的位置:首页 > 编程语言 > C语言/C++

第十五周项目 补充阅读程序(4)

2016-06-07 14:56 387 查看
/*
*Copyright(c) 2016, 烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作    者:李德坤
*完成日期:2016年6月7日
*版本号:v1.0
*
*问题描述:补充阅读(4)
*输入描述:无
*输出描述:无
*/
#include <algorithm>
#include<map>
#include<iterator>
#include<iostream>
#include<cstring>
using namespace std;
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};

int main()
{
map<const char*, int, ltstr> months;

months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;

cout << "june -> " << months["june"] << endl;
map<const char*, int, ltstr>::iterator cur  = months.find("june");
map<const char*, int, ltstr>::iterator prev = cur;
map<const char*, int, ltstr>::iterator next = cur;
++next;
--prev;
cout << "Previous (in alphabetical order) is " << (*prev).first << endl;
cout << "Next (in alphabetical order) is " << (*next).first << endl;
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++