当前位置:网站首页>1041 be unique (20 points (s)) (hash: find the first number that occurs once)
1041 be unique (20 points (s)) (hash: find the first number that occurs once)
2022-07-06 12:33:00 【Vigorous waist Nuo dance】
title
Ideas
Two things are needed : One is a table that records the sequence , One is a table that records the number of times
Code
#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";
}
doubt
I don't know why I'm wrong ╮(╯_╰)╭
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;
}
边栏推荐
- Expected value (EV)
- [Offer29] 排序的循环链表
- Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
- NRF24L01故障排查
- (4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
- [Offer18]删除链表的节点
- JS regular expression basic knowledge learning
- JS variable types and common type conversions
- AMBA、AHB、APB、AXI的理解
- Servlet
猜你喜欢

Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights

Types de variables JS et transformations de type communes

ES6 grammar summary -- Part I (basic)

ESP8266连接onenet(旧版MQTT方式)

ARM PC=PC+8 最便于理解的阐述
![[esp32 learning-2] esp32 address mapping](/img/ee/c4aa0f7aed7543bb6807d7fd852c88.png)
[esp32 learning-2] esp32 address mapping

Walk into WPF's drawing Bing Dwen Dwen

程序设计大作业:教务管理系统(C语言)

idea中好用的快捷键

Redis based distributed ID generator
随机推荐
[Offer29] 排序的循环链表
ESP8266连接onenet(旧版MQTT方式)
Conditional probability
Arduino uno R3 register writing method (1) -- pin level state change
Single chip Bluetooth wireless burning
JS variable types and common type conversions
.elf .map .list .hex文件
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
Important methods of array and string
Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
[esp32 learning-1] construction of Arduino esp32 development environment
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
1081 rational sum (20 points) points add up to total points
Mysqldump error1066 error solution
History object
open-mmlab labelImg mmdetection
Rough analysis of map file
Arduino JSON data information parsing
Pat 1097 duplication on a linked list (25 points)
Common properties of location