結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 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:39:26: warning: ‘rank’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |     else cout << rank << "th" << 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) cout << "1st" << endl;
    else if(rank == 2) cout << "2nd" << endl;
    else if(rank == 3) cout << "3rd" << endl;
    else cout << rank << "th" << endl;

    //for(int i = 0; i < n; i++) cout << height[i] << " ";

    return 0;


}
0