2 תשובות
שואל השאלה:
#include <iostream>
#include <unordered_map>

int main() {
int n;
int target;
int temp;
int index1=0;
int index2=0;
std::unordered_map<int, int> arr1;
std::cin >> n;
std::cin >> target;
for(int i=0;i<n;++i) {
std::cin >> temp;
if (target == 1) {
continue;
}
if (target-temp < 0) {
continue;
}
else {
arr1.insert({temp, i+1});
auto it = arr1.find(target-temp);
if (it != arr1.end()) {
if (it->second == arr1[temp]) {
continue;
}
index1 = it->second;
index2 = arr1[temp];
}
}
}
if (index1 == 0 & index2 == 0) {
std::cout << "impossible";
}
else {
std::cout << index1 << " " << index2;
}
}








הקוד שלי
שואל השאלה:
את הערך כאשר יש 2 מפתחות אותו דבר