第 2 期:忘记业余项目,专注于工作
Weekly #2

Table of Contents
algorithm ⬆
1. 句子逆序
2. 根据快速排序的思路,找出数组中第 K 大的数
review ⬆
tip ⬆
share ⬆
最后更新于

最后更新于
def reverse_words():
return " ".join(input().split()[::-1])
print(reverse_words())class Finder {
public:
int findKth(vector<int> a, int n, int K) {
return findKth(a, 0, n - 1, n - K + 1);
}
int findKth(vector<int>&a, int l, int r, int K) {
if (l == r) return a[l];
int i = l - 1, j = r + 1;
int x = a[l + r >> 1];
while (i < j) {
do i++; while (a[i] < x);
do j--; while (x < a[j]);
if (i < j) swap(a[i], a[j]);
}
int s = j - l + 1;
if (K <= s) return findKth(a, l, j, K);
else return findKth(a, j + 1, r, K - s);
}
};template < class Key, // unordered_map::key_type
class T, // unordered_map::mapped_type
class Hash = hash<Key>, // unordered_map::hasher
class Pred = equal_to<Key>, // unordered_map::key_equal
class Alloc = allocator< pair<const Key, T> > // unordered_map::allocator_type
>
class unordered_map;// TEMPLATE STRUCT hash
template<class _Kty>
struct hash: public _Bitwise_hash<_Kty> {
static constexpr bool _Value = __is_enum(_Kty);
static_assert(_Value,
"The C++ Standard doesn't provide a hash for this type.");
};
template<>
struct hash<bool>: public _Bitwise_hash<bool> {
// hash functor for bool
};
template<>
struct hash<char>: public _Bitwise_hash<char> {
// hash functor for char
};struct pair_hash {
template<class T1, class T2>
std::size_t operator() (const std::pair<T1, T2>& p) const {
auto h1 = std::hash<T1> {}(p.first);
auto h2 = std::hash<T2> {}(p.second);
return h1 ^ h2;
}
};
int main() {
//unordered_map<pair<int, int>, int> error_mmp; // error
unordered_map<pair<int, int>, int, pair_hash> ok_mmp; // ok
}jobs:
format:
runs-on: ubuntu-latest
if: "contains(github.event.head_commit.message, '[build]')"jobs:
format:
runs-on: ubuntu-latest
if: "! contains(github.event.head_commit.message, 'wip')"