結果

問題 No.564 背の順
ユーザー hamrayhamray
提出日時 2017-11-04 18:15:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 679 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 65,420 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 22:47:34
合計ジャッジ時間 1,407 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 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:28:24: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |         cout << ans << "th" << endl;
      |                        ^~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int H, N; cin >> H >> N;
    int height;
    int ans;
    vector<int> v;
    for(int i = 0; i < N - 1; i++){
        cin >> height;
        v.push_back(height);
    }
    v.push_back(H);
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for(int i = 0; i < N; i++){
        if(v[i] == H)
            ans = i + 1;
    }
    if(ans == 1){
        cout << ans << "st" << endl; 
    }else if(ans == 2){
        cout << ans << "nd" << endl; 
    }else if(ans == 3){
        cout << ans << "rd" << endl; 
    }else{
        cout << ans << "th" << endl;
    
}   return 0;
}
0