7-1 统计工龄 (20 分)
#include<bits/stdc++.h>
#define eb emplace_back
#define PSI pair<string,int>
const int N = 2e5 + 10;
#define x first
#define y second
using namespace std;
set<int>st;
int num[N];
void solve(){
int n;
cin>>n;
int x;
for(int i=1;i<=n;i++){
cin>>x;
st.insert(x);
num[x]++;
}
for(auto i:st){
cout<<i<<":"<<num[i]<<endl;
}
}
int main(){
solve();
return 0;
}
7-2 寻找大富翁 (25 分)
#include <bits/stdc++.h>
using namespace std;
priority_queue<int> p;
int main()
{
int n,m,a;
scanf("%d%d",&n,&m);
int flag=0,flag1=0;
for(int i=0; i<n; i++)
{
scanf("%d",&a);
p.push(a);
}
if(m>n)
{
while(p.size()>=1)
{
if(flag==0)
{
printf("%d",p.top());
p.pop();
flag=1;
}
else
{
printf(" %d",p.top());
p.pop();
}
}
}
else
{
for(int i=0;i<m;i++)
{
if(flag1==0)
{
printf("%d",p.top());
p.pop();
flag1=1;
}
else
{
printf(" %d",p.top());
p.pop();
}
}
}
return 0;
}
7-3 点赞狂魔 (25 分)
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
const int N = 1e7 + 10;
using namespace std;
struct node
{
string s;
int sum;
double ave;
node(string s1,int sum1,double ave1):s(s1),sum(sum1),ave(ave1) {
}
};
bool cmp(node x,node y)
{
if(x.sum==y.sum)
return x.ave