0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

tupleをvectorに格納してsort

Last updated at Posted at 2020-11-10

AtCoder ABC128 B問題( https://atcoder.jp/contests/abc128/tasks/abc128_b )で使った。tupleの第二要素→第三要素の順でsortしているが,前者は辞書順(昇順),後者は降順である。

main.cpp
//main外
typedef tuple<int, string, int> mytuple;
 
//main内
vector<mytuple> V;
auto condition = [](mytuple &alpha, mytuple &beta){
  if(get<1>(alpha) != get<1>(beta)) return get<1>(alpha) < get<1>(beta);
  return get<2>(alpha) > get<2>(beta);
});
sort(V.begin(), V.end(), condition);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?