map的简单使用

简单的谁先开门关门
/*
map简单的使用
恩 还有就是map.count(k)  就是指k这个元素有没有在这个map里面
第一个是键  第二个是值
*/

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
map<string,string>mp1,mp2;
string name,begintime,endtime;
int main()
{
	int n;
	scanf("%d",&n);
    for(int i=1;i<=n;i++)    	
    {
    	cin>>name>>begintime>>endtime;
    	mp1[begintime]=name;
    	mp2[endtime]=name;
    }
    map<string,string>::iterator it1=mp1.begin();
    map<string,string>::iterator it2=mp2.end();
    it2--;
    cout<<it1->second<<endl;
    cout<<it2->second<<endl;
	return 0;
}



#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct node
{
	char name[20];
	char begin[10];
	char end[10];
}what[200];
bool cmp1(node a,node b)
{
	return strcmp(a.begin,b.begin)==-1;
}
bool cmp2(node a,node b)
{
	return strcmp(a.begin,b.begin)==1;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	   scanf("%s %s %s",what[i].name,what[i].begin,what[i].end);
    sort(what+1,what+1+n,cmp1);
    printf("%s\n",what[1].name);
    sort(what+1,what+1+n,cmp2);
    printf("%s\n",what[1].name);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值