2
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?

競プロ日記#25/07/07

Posted at

AtCoder

AtCoder Beginner Contest 128

B - Guidebook

  • APG4bの練習問題
  • Pairを入れ子構造にした配列を用意することでソートの二段階目を可能にしている。ちなみに俺はTupleを使うという大見当違いをかまして実装できなかった
  • first.first (1番目のソート基準) に string 型で市名を入れ、first.second (2 番目のソート基準) に int 型で点数の −1 倍を入れる。-1倍することで高い順にソートできる。
    ちなみにこのやり方ならTupleでもいけるんじゃね?ってこの記事書きながら思った


int main() {
    long long N;
    cin >> N;
    vector<tuple<string, long long, long long>> SandP(N);
    for (long long i = 0; i < N; i++) {
        long long Score;
        cin >> get<0>(SandP[i]) >> Score;
        get<1>(SandP[i]) = -1 * Score;
        get<2>(SandP[i]) = (i + 1);
    }
    sort(SandP.begin(), SandP.end());
    
    for (long long i = 0; i < N; i++) {
        cout << get<2>(SandP[i]) << endl;
    }   
}

イケた。

2
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
2
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?