OSDN Git Service
(root)
/
oi-wiki
/
main.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
dc50117
)
Added an example of combining sort and unique.
author
sbofgayschool
<1532422769@qq.com>
Tue, 10 Nov 2020 07:08:46 +0000
(15:08 +0800)
committer
sbofgayschool
<1532422769@qq.com>
Tue, 10 Nov 2020 07:08:46 +0000
(15:08 +0800)
docs/lang/csl/algorithm.md
patch
|
blob
|
history
diff --git
a/docs/lang/csl/algorithm.md
b/docs/lang/csl/algorithm.md
index
01ba659
..
496feec
100644
(file)
--- a/
docs/lang/csl/algorithm.md
+++ b/
docs/lang/csl/algorithm.md
@@
-73,3
+73,12
@@
if (i == 0 || (i < n && a[i] - x < x - a[i - 1]))
else
cout << a[i - 1];
```
+
+- 使用 `sort` 与 `unique` 查找数组 `a` 中 **第 $k$ 大的值** (重复出现的值仅算一次)。
+
+```cpp
+sort(a, a + n);
+// unique将返回去重之后数组最后一个元素之后的地址,计算出的cnt为去重后数组的长度
+int cnt = unique(a, a + n) - a;
+cout << a[k - 1];
+```