結果

問題 No.564 背の順
コンテスト
ユーザー pinebooks
提出日時 2017-09-08 22:54:53
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 664 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 541 ms
コンパイル使用メモリ 71,316 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-07 20:37:56
合計ジャッジ時間 1,509 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:27:12: warning: 'rank' may be used uninitialized [-Wmaybe-uninitialized]
   27 |   if (rank % 10 == 1)
      |       ~~~~~^~~~
main.cpp:19:7: note: 'rank' was declared here
   19 |   int rank;
      |       ^~~~

ソースコード

diff #
raw source code

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

int main() {
  vector<int> heights;
  int H, N;
  scanf("%d%d", &H, &N);
  heights.push_back(H);
  for (int i = 1; i < N; i++) {
    int hi;
    scanf("%d", &hi);
    heights.push_back(hi);
  }
  sort(heights.begin(), heights.end(), greater<int>());
  int rank;
  for (int i = 0; i < N; i++) {
    if (heights[i] == H) {
      rank = i + 1;
      break;
    }
  }

  if (rank % 10 == 1)
    printf("%dst\n", rank);
  else if (rank % 10 == 2)
    printf("%dnd\n", rank);
  else if (rank % 10 == 3)
    printf("%drd\n", rank);
  else
    printf("%dth\n", rank);
}
0