結果

問題 No.564 背の順
ユーザー pinebookspinebooks
提出日時 2017-09-08 22:54:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 64,272 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-07 08:32:06
合計ジャッジ時間 1,065 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,504 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:12: warning: ‘rank’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (rank % 10 == 1)
       ~~~~~^~~~

ソースコード

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;
  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