結果

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

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

void bsort(int n, int A[]){
    int flag = 1;
    while(flag){
        for(int i = n-1; i > 0 ; i--){
            flag = 0;
            if(A[i] < A[i-1]){
                int temp = A[i];
                A[i] = A[i-1];
                A[i-1] = temp;
                flag = 1;
            }
        }
    }
    return;
}

int main(){
    int nama, n;
    cin >> nama >> n;

    int height[n];
    for(int i = 1; i < n; i++) cin >> height[i];
    height[0] = nama;
    bsort(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