目录
- t1.统计数字
- t2.
2水题 + 1中等 + 1稍难
t1.统计数字
题意:给定n个数,按数字从小到大的顺序输出数字及出现次数。
思路:[水题]爱怎么搞怎么搞,反正我就是要用优先队列。
Code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
//Mystery_Sky
//
#define INF 0x3f3f3f3f
#define M 1000100
#define ll long long
inline int read()
{
int x=0,f=1; char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int n;
struct node{
int x;
inline bool operator <(const node& a) const{
return a.x < x;
}
};
priority_queue <node> Q;
int main() {
n = read();
for(int i = 1; i <= n; i++) {
int x = read();
Q.push((node){x});
}
node last = Q.top();
Q.pop();
int count = 1;
while(!Q.empty()) {
node top = Q.top();
Q.pop();
if(top.x == last.x) count++;
else {
printf("%d %d\n", last.x, count);
count = 1;
last = top;
}
//printf("->%d %d<-\n", top.x, count);
}
printf("%d %d\n", last.x, count);
return 0;
}
t2.
原文地址:https://www.cnblogs.com/Benjamin-cpp/p/11745332.html
时间: 2024-10-11 15:24:14