Solutions of Ascending - MarisaOJ: Marisa Online Judge

Solutions of Ascending

Select solution language

Write solution here.


ducyn    Created at    1 likes

**Hint**: **Cách 1:** - if else xét từng trường hợp --------- **Cách 2:** - Sử dụng hàm *sort* có sẵn trong thư viện *Note: nên dùng cách 2 vì ngắn hơn (tiết kiệm thời gian viết code :>> ) --------- Code tham khảo **Cách 1**: ```cpp #include <bits/stdc++.h> #define ll long long #define name "TASK" #define TIME (1.0 * clock() / CLOCKS_PER_SEC) using namespace std; void solve(){ int a, b, c; cin>>a>>b>>c; if(a<=b && a<=c){ if(b<=c) cout<<a<<" "<<b<<" "<<c; else cout<<a<<" "<<c<<" "<<b; } else if(b<=a && b<=c){ if(a<=c) cout<<b<<" "<<a<<" "<<c; else cout<<b<<" "<<c<<" "<< a; } else{ if(a<=b) cout<<c<<" "<<a<<" "<<b; else cout<<c<<" "<<b<<" "<<a; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(fopen(name".INP","r")) { freopen(name ".INP","r",stdin); freopen(name ".OUT","w",stdout); } solve(); cerr << '\n' << "Time collapsed: " << TIME << '\n'; return 0; } ``` --------- Code tham khảo **Cách 2**: ```cpp #include <bits/stdc++.h> #define ll long long #define name "TASK" #define TIME (1.0 * clock() / CLOCKS_PER_SEC) using namespace std; void solve(){ int a, b, c; cin>>a>>b>>c; int e[]={a, b, c}; sort(e, e+3); for(int i=0;i<3;i++){ cout<<e[i]<<" "; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(fopen(name".INP","r")) { freopen(name ".INP","r",stdin); freopen(name ".OUT","w",stdout); } solve(); cerr << '\n' << "Time collapsed: " << TIME << '\n'; return 0; } ```