最大数量
题目 最大数量
思路分析
可以把时间当字符串存 也可以换算成分钟存
当字符串的话 就是借鉴第一题 中间加个空格 然后又要计数 借鉴第二题 把string当键 int当值记录每个出现的次数
转换成分的话 直接值做下标计数即可(桶排序)
代码实现
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,int> h;
int n;
int main()
{
cin>>n;
int res=0;
while(n--)
{
string hh,mm;
cin>>hh>>mm;
string key=hh+' '+mm;
h[key]++;
res=max(res,h[key]);
}
cout<<res;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N=1500;
int n;
int cnt[N];
int main()
{
cin>>n;
int res=0;
while(n--)
{
int hh,mm;
cin>>hh>>mm;
int time=hh*60+mm;
cnt[time]++;
res=max(res,cnt[time]);
}
cout<<res;
return 0;
}
💬 评论