当前位置:网站首页>1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
2022-07-06 09:18:00 【劲腰傩舞】
标题
思路
需要两样东西:一个是记录顺序的表,一个是记录次数的表
代码
#include <iostream>
using namespace std;
int hashtable[100100], num[100100];
#define rep(i,j,k) for(int i=j;i<k;i++)
int main() {
int n;
cin >> n;
rep(i, 0, n) {
cin >> num[i];
hashtable[num[i]]++;
}
rep(i, 0, n)
if (hashtable[num[i]] == 1) {
cout << num[i];
return 0;
}
cout << "None";
}
疑惑
不清楚为什么错了╮(╯_╰)╭
using namespace std;
#include <unordered_map>
#define rep(i,j,k) for(int i=j;i<k;i++)
#include <iostream>
int main() {
unordered_map<int, int>bets;
int n, temp;
cin >> n;
rep(i, 0, n) {
cin >> temp;
bets[temp]++;
}
for (auto i : bets) {
//cout << i.second << endl;
if (i.second == 1) {
cout << i.first;
return 0;
}
}
cout << "None";
return 0;
}
边栏推荐
- Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
- GCC compilation options
- Arduino JSON data information parsing
- Dead loop in FreeRTOS task function
- RuntimeError: cuDNN error: CUDNN_ STATUS_ NOT_ INITIALIZED
- MySQL时间、时区、自动填充0的问题
- Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
- 关于Gateway中使用@Controller的问题
- What is the maximum length of MySQL varchar field
- Basic operations of databases and tables ----- creating data tables
猜你喜欢
[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data
History object
Latex learning
JS 函数提升和var变量的声明提升
level16
First use of dosbox
(1) Introduction Guide to R language - the first step of data analysis
[esp32 learning-1] construction of Arduino esp32 development environment
Basic operations of databases and tables ----- view data tables
Learning notes of JS variable scope and function
随机推荐
NRF24L01 troubleshooting
C language, log print file name, function name, line number, date and time
[899]有序队列
ORA-02030: can only select from fixed tables/views
@The difference between Autowired and @resource
[Offer18]删除链表的节点
Single chip Bluetooth wireless burning
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
[offer78] merge multiple ordered linked lists
Redis based distributed locks and ultra detailed improvement ideas
JS数组常用方法的分类、理解和运用
JS regular expression basic knowledge learning
Expected value (EV)
Imgcat usage experience
The first simple case of GNN: Cora classification
Redis cache update strategy, cache penetration, avalanche, breakdown problems
Flink late data processing (3)
RT thread API reference manual
Redis based distributed ID generator
[offer9]用两个栈实现队列