当前位置:网站首页>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;
}
边栏推荐
- 【ESP32学习-2】esp32地址映射
- Several declarations about pointers [C language]
- ES6语法总结--下篇(进阶篇 ES6~ES11)
- Pat 1097 duplication on a linked list (25 points)
- ES6语法总结--上篇(基础篇)
- JS正则表达式基础知识学习
- Amba, ahb, APB, Axi Understanding
- MySQL时间、时区、自动填充0的问题
- Navigator object (determine browser type)
- [Red Treasure Book Notes simplified version] Chapter 12 BOM
猜你喜欢

【ESP32学习-1】Arduino ESP32开发环境搭建

Pytorch four commonly used optimizer tests

MySQL占用内存过大解决方案

JS regular expression basic knowledge learning

MySQL takes up too much memory solution

Whistle+switchyomega configure web proxy

Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
![[esp32 learning-2] esp32 address mapping](/img/ee/c4aa0f7aed7543bb6807d7fd852c88.png)
[esp32 learning-2] esp32 address mapping

Basic operations of databases and tables ----- modifying data tables

RT thread API reference manual
随机推荐
Get the position of the nth occurrence of the string
程序员老鸟都会搞错的问题 C语言基础 指针和数组
如何给Arduino项目添加音乐播放功能
C language, log print file name, function name, line number, date and time
RuntimeError: cuDNN error: CUDNN_ STATUS_ NOT_ INITIALIZED
Programmers can make mistakes. Basic pointers and arrays of C language
Gateway fails to route according to the service name, and reports an error service unavailable, status=503
What is the maximum length of MySQL varchar field
Walk into WPF's drawing Bing Dwen Dwen
[offer78] merge multiple ordered linked lists
Kaggle competition two Sigma connect: rental listing inquiries
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
数据库课程设计:高校教务管理系统(含代码)
Amba, ahb, APB, Axi Understanding
[offer9]用两个栈实现队列
Working principle of genius telephone watch Z3
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
JS数组常用方法的分类、理解和运用
Basic operations of databases and tables ----- creating data tables
Arduino JSON data information parsing