Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int n = 0;
- int *pArray = nullptr;
- int arrResult[3] = {-1, -1, -1};
- cout << "Input n: ";
- cin >> n;
- if(n > 0){
- pArray = new int[n]{};
- }
- for(int i = 0; i<n; i++){
- cin >> pArray[i];
- }
- for(int i = 0; i<n; i++){
- if (pArray[i] > arrResult[0]){
- arrResult[2] = arrResult[1];
- arrResult[1] = arrResult[0];
- arrResult[0] = pArray[i];
- }else if(pArray[i] > arrResult[1]){
- arrResult[2] = arrResult[1];
- arrResult[1] = pArray[i];
- continue;
- }else if(pArray[2] > arrResult[1]){
- arrResult[2] = pArray[i];
- continue;
- }
- }
- if(pArray != nullptr)
- {
- delete[] pArray;
- }
- cout << "#output\n[" ;
- if(arrResult[0] != -1){
- cout<< arrResult[0];
- }
- if(arrResult[1] != -1){
- cout << ", " << arrResult[1];
- }
- if(arrResult[2] != -1){
- cout << ", " << arrResult[2] << "]\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement