結果
| 問題 |
No.564 背の順
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-04 23:04:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 916 bytes |
| コンパイル時間 | 369 ms |
| コンパイル使用メモリ | 54,772 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-28 04:32:38 |
| 合計ジャッジ時間 | 863 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 3 WA * 6 |
コンパイルメッセージ
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;
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;
}