当前位置:网站首页>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;
}
边栏推荐
- Common DOS commands
- Navigator object (determine browser type)
- CUDA C programming authoritative guide Grossman Chapter 4 global memory
- [leetcode19]删除链表中倒数第n个结点
- STM32 how to locate the code segment that causes hard fault
- [offer78] merge multiple ordered linked lists
- MySQL時間、時區、自動填充0的問題
- JS variable types and common type conversions
- JS正则表达式基础知识学习
- [Offer29] 排序的循环链表
猜你喜欢
Time slice polling scheduling of RT thread threads
单片机蓝牙无线烧录
(一)R语言入门指南——数据分析的第一步
程序设计大作业:教务管理系统(C语言)
Expected value (EV)
Basic operations of databases and tables ----- creating data tables
(1) Introduction Guide to R language - the first step of data analysis
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
Priority inversion and deadlock
Latex learning
随机推荐
PT OSC deadlock analysis
Pytoch implements simple linear regression demo
2021.11.10 compilation examination
First use of dosbox
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
[offer78] merge multiple ordered linked lists
Fashion Gen: the general fashion dataset and challenge paper interpretation & dataset introduction
Redis based distributed locks and ultra detailed improvement ideas
By v$rman_ backup_ job_ Oracle "bug" caused by details
如何给Arduino项目添加音乐播放功能
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
ES6 grammar summary -- Part I (basic)
單片機藍牙無線燒錄
RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
RT thread API reference manual
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
[offer9]用两个栈实现队列
(一)R语言入门指南——数据分析的第一步