結果
問題 | No.750 Frac #1 |
ユーザー |
![]() |
提出日時 | 2019-02-08 12:17:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,055 bytes |
コンパイル時間 | 556 ms |
コンパイル使用メモリ | 68,752 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 20:12:09 |
合計ジャッジ時間 | 1,710 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<iostream> #include<vector> #include<stdlib.h> using namespace std; typedef struct frac { double A; double B; double result; // a/bの値 } frac; void run(); void sort_list(int n, struct frac *pt); int main() { run(); return EXIT_SUCCESS; } void run() { int n; cin>>n; frac f[10]={{-100,-100,-100}}; //ありえない値にしておく for(int i=0;i<n;i++){ cin>>f[i].A>>f[i].B; f[i].result=f[i].A/f[i].B; } //並び替え sort_list(n,f); } void sort_list(int length, struct frac *pt) { /* 構造体をtmpを使ってソートする https://teratail.com/questions/52359 */ struct frac tmp; for(int i=0; i<length; i++){ for(int j=length-1; j>i; j--){ if((pt+j)->result > (pt+j-1)->result){ tmp = *(pt+j); *(pt+j) = *(pt+j-1); *(pt+j-1) = tmp; } } } for(int i=0; i<length; i++){ cout<<pt[i].A<<" "<<pt[i].B<<" "<<endl; } }