#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> arr;
int min = 9999999;
for(int i = 0; i<N; ++i) {
int temp;
cin >> temp;
arr.push_back(temp);
}
for(int i = 0; i<arr.size(); ++i) {
if(arr[i]<min) {
min = arr[i];
cout << "Min 1: " << min;
int min2 = 9999999;
if(arr[i]<min2&&arr[i]!=min) {
min2 = arr[i];
cout << endl << "Min 2: " << min2;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> arr;
int min = 9999999;
for(int i = 0; i<N; ++i) {
int temp;
cin >> temp;
arr.push_back(temp);
}
for(int i = 0; i<arr.size(); ++i) {
if(arr[i]<min) {
min = arr[i];
}
}
cout << "Min 1: " << min;
int min2 = 9999999;
for(int i = 0; i<arr.size(); ++i) {
if(arr[i]<min2&&arr[i]!=min) {
min2 = arr[i];
}
}
cout << endl << "Min 2: " << min2;
}