結果
問題 |
No.564 背の順
|
ユーザー |
|
提出日時 | 2017-12-04 22:49:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 857 bytes |
コンパイル時間 | 434 ms |
コンパイル使用メモリ | 54,908 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-28 04:32:23 |
合計ジャッジ時間 | 1,051 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 9 |
コンパイルメッセージ
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; | ^~~~
ソースコード
#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+1; 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; return 0; }