• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Bài 3

anhnv Feb 23rd, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. using namespace std;
3.
4. int main(){
5.     int n = 0;
6.     int *pArray = nullptr;
7.     int arrResult[3] = {-1, -1, -1};
8.
9.     cout << "Input n: ";
10.     cin >> n;
11.
12.     if(n > 0){
13.         pArray = new int[n]{};
14.     }
15.
16.     for(int i = 0; i<n; i++){
17.         cin >> pArray[i];
18.     }
19.
20.
21.     for(int i = 0; i<n; i++){
22.         if (pArray[i] > arrResult[0]){
23.             arrResult[2] = arrResult[1];
24.             arrResult[1] = arrResult[0];
25.             arrResult[0] = pArray[i];
26.         }else if(pArray[i] > arrResult[1]){
27.             arrResult[2] = arrResult[1];
28.             arrResult[1] = pArray[i];
29.             continue;
30.         }else if(pArray[2] > arrResult[1]){
31.             arrResult[2] = pArray[i];
32.             continue;
33.         }
34.     }
35.
36.     if(pArray != nullptr)
37.     {
38.         delete[] pArray;
39.
40.     }
41.
42.     cout << "#output\n[" ;
43.     if(arrResult[0] != -1){
44.         cout<< arrResult[0];
45.     }
46.     if(arrResult[1] != -1){
47.         cout << ", " << arrResult[1];
48.        }
49.     if(arrResult[2] != -1){
50.            cout << ", " << arrResult[2] << "]\n";
51.     }
52.
53.     return 0;
54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top