Solutions of The smallest and biggest - MarisaOJ: Marisa Online Judge

Solutions of The smallest and biggest

Select solution language

Write solution here.


ducyn    Created at    1 likes

**Cách 1**: - if else xét trường hợp -------- **Cách 2**: - Dùng hàm *max* và *min* có sẵn trong thư viện -------- 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; int mn = a, mx = a; if(b < mn) mn = b; if(c < mn) mn = c; if(b > mx) mx = b; if(c > mx) mx = c; cout<<mn<<" "<<mx<<'\n'; } 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 mn=min({a, b, c}); int mx=max({a, b, c}); cout<<mn<<" "<<mx<<'\n'; } 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; } ```