結果
| 問題 | No.564 背の順 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-12-04 23:30:55 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 988 bytes | 
| コンパイル時間 | 497 ms | 
| コンパイル使用メモリ | 56,056 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-28 04:34:09 | 
| 合計ジャッジ時間 | 1,141 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 9 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:31: warning: ‘rank’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |     else if(rank == 3 || (rank-3)%10 == 0) cout << rank << "rd" << endl;
      |                          ~~~~~^~~
            
            ソースコード
#include <iostream>
using namespace std;
void selection_sort(int n, int A[]){
    for(int i = 0; i < n; i++){
        int minj = i;
        for(int j = i; j < n; j++){
            if(A[minj] > A[j]){
                minj = j;
            }
        }
        int temp = A[minj];
        A[minj] = A[i];
        A[i] = temp;
    }
    return;
}
int main(){
    int nama, n;
    cin >> nama >> n;
    int height[n];
    height[0] = nama;
    for(int i = 1; i < n; i++) cin >> height[i];
    selection_sort(n,height);
    int rank;
    for(int i = 0; i < n ; i++){
        if(height[i] == nama){
            rank = n-i;
            break;
        }
    }
    if(rank == 1 || (rank-1)%10 == 0) cout << rank << "st" << endl;
    else if(rank == 2 || (rank-2)%10 == 0) cout << rank << "nd" << endl;
    else if(rank == 3 || (rank-3)%10 == 0) cout << rank << "rd" << endl;
    else cout << rank << "th" << endl;
    //for(int i = 0; i < n; i++) cout << height[i] << " ";
    return 0;
}
            
            
            
        