結果

問題 No.564 背の順
ユーザー NoiriNoiri
提出日時 2017-12-04 23:30:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 55,032 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 02:23:18
合計ジャッジ時間 1,508 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |                          ~~~~~^~~

ソースコード

diff #

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


}
0