当前位置:网站首页>CCF numerical sorting (Full Score code + problem solving ideas + skill summary) 201503-2
CCF numerical sorting (Full Score code + problem solving ideas + skill summary) 201503-2
2022-06-30 14:41:00 【A cute little monkey】
Skill summary
For numerical pairs , An ascending order , A descending order , Use structures to store , Overloaded comparison function can be implemented ( The same is true for sorting multiple values )
Title Description

Their thinking
- The data range is small , So we can use Count the array subscripts
- For numerical pairs , use Structure storage , Overload comparison function , Sort
Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int a[N];
struct data
{
int n;
int c;
bool operator< (const data& t) const // Overloads the comparison function so that it is in descending order of the number of times , The values are in ascending order
{
if(c != t.c) return c > t.c;
else return n < t.n;
}
}s[N];
int main()
{
int n;
cin >> n;
int x = 0;
for (int i = 0; i < n; i ++)
{
cin >> x;
a[x] ++; // Using the properties of hash table and subscript to count
}
int cnt = 0;
for (int i = 0; i < N; i ++) // Notice that this is N
{
if (a[i])
{
s[cnt ++ ] = {
i, a[i]}; // take ( Numbers , The number of times the number appears ) Store in structure
}
}
sort(s, s + cnt);
for (int i = 0; i < cnt; i ++)
{
cout << s[i].n << " " << s[i].c << endl;
}
return 0;
}
边栏推荐
- JS delete the objects in the array and specify to delete the objects
- Minimum covering substring of two pointers
- 【BUUCTF】 EasySql
- Judgment of deep learning experiment results
- Att & CK red team evaluation field (I)
- 2021 geek challenge Web
- Ctfshow getting started with the web (ThinkPHP topic)
- Introduction to the construction and development of composer private warehouse
- Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~
- 2021-08-05 leetcode notes
猜你喜欢

XSS challenge (6-10) more detailed answers

2021-05-12

Knowledge learned from the water resources institute project

Initial attack and defense world Misc

How to use Alibaba Vector Icon

MySQL back to table query optimization

Race of golang

LIS error: this configuration section cannot be used in this path

remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac

DiceCTF - knock-knock
随机推荐
Laravel8 custom log directory, rename
Mutex lock, read / write lock, spin lock, pessimistic lock, and optimistic lock
V3 01_ Welcome
[geek challenge 2019] PHP problem solving record
notepad正则删除关键词所在行
[extensive reading of papers] attributes guided facial image completion
CCF window (Full Score code + problem solving idea) March 2, 2014
Thoughts on the security of a PHP file name regular verification
Data recovery software easyrecovery15 Download
JS time conversion standard format, timestamp conversion standard format
PS cutting height 1px, Y-axis tiling background image problem
DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
【BUUCTF】 Have Fun
Advanced usage of go language for loop break and continue
2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
【BUUCTF】 EasySql
Finding the median of two arrays by dichotomy
从控制层返回到js的json数据带“\”转译符,怎么去掉
Maximum area of islands searched
Double pointer circular linked list