結果

問題 No.564 背の順
ユーザー pinebookspinebooks
提出日時 2017-09-08 22:48:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 645 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 49,604 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 20:48:24
合計ジャッジ時間 991 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |   scanf("%d%d", &H, &N);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     scanf("%d", &hi);
      |     ~~~~~^~~~~~~~~~~

ソースコード

diff #

#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 = 0;
  for (int i = 0; i < N; i++) {
    if (heights[i] == H) {
      rank = i + 1;
      break;
    }
  }

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