結果
| 問題 |
No.564 背の順
|
| コンテスト | |
| ユーザー |
pinebooks
|
| 提出日時 | 2017-09-08 22:54:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 664 bytes |
| コンパイル時間 | 570 ms |
| コンパイル使用メモリ | 49,732 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 12:11:46 |
| 合計ジャッジ時間 | 1,117 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~~
main.cpp:27:12: warning: ‘rank’ may be used uninitialized in this function [-Wmaybe-uninitialized]
27 | if (rank % 10 == 1)
| ~~~~~^~~~
ソースコード
#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);
}
pinebooks