【OJ】C++,Java,Python,Go,Rust

for循环语法

// cpp

// java

// python
for i in range(集合):
for i, val in enumerate(集合):
for v1,v2,v3,... in zip(集合1,集合2,集合3,...):

Pair

// cpp
pair<int, string> first second
// java
Pair<Integer, String> first() 
new Pair<>(firstVal, secondVal)

### 有序集合
```cpp
// cpp
set
方法:
- insert
- erase

// java
new TreeSet<,>()
创建一个TreeSet,定义其比较规则:
new TreeSet<>((a, b) -> 
    !Objects.equals(a.getKey(), b.getKey()) ? 
        b.getKey() - a.getKey() : // 逆序 
        a.getValue().compareTo(b.getValue())
    )


// python
from sortedcontainers import SortedSet
方法:
- remove
- add

优先队列

Map<String, Queue<Pair<Integer, String>>> cs = new HashMap<>();

cs.computeIfAbsent(c, k -> new PriorityQueue<>((a, b) -> 
!Objects.equals(a.getKey(), b.getKey()) ? 
    b.getKey() - a.getKey() : // 逆序 
    a.getValue().compareTo(b.getValue())
)).add(new Pair<>(r, f));

综合

在一个 Map 中放置一个 TreeSet

Map<String, TreeSet<Pair<Integer, String>>> cs = new HashMap<>();
cs.computeIfAbsent(c, k -> new TreeSet<>((a, b) -> 
    !Objects.equals(a.getKey(), b.getKey()) ? 
        b.getKey() - a.getKey() : // 逆序 
        a.getValue().compareTo(b.getValue())
    )).add(new Pair<>(r, f));

猜你喜欢

转载自blog.csdn.net/myRealization/article/details/135442719