li = []
elements = 1
negative_index = 0
positive_index = 0
print("Введите 0 что бы остановить ввод")
while elements != 0:
elements = int(input("Введите элементы списка\n"))
li.append(elements)
li2 = li[:]
li2.sort()
length = li.__len__()
print(li)
for i in range(0, length-1):
for j in range(length-1, 1, -1):
if li2[i] * (-1) == li2[j]:
for k in range(0, length-1):
if li2[i] == li[k]:
negative_index = k
if li2[j] == li[k]:
positive_index = k
if negative_index < positive_index:
print("Индекс противоположного числа(1) ->", negative_index)
print("Индекс противоположного числа(2) ->", positive_index)
elif negative_index == positive_index == 0:
exit(0)
else:
print("Индекс противоположного числа(1) ->", positive_index)
print("Индекс противоположного числа(2) ->", negative_index)
P.S
Код не идеальный, но задачу выполняет
/*
Выводы перед вводом данных(cout) можно убрать (сделал для удобства)
*/
#include <iostream>
#include <vector>
#define UNITS '$' // <- Валюта
using namespace std;
int main()
{
int SWEETS, COOKIES, APPLES;
cout<<"Price for 1 kg of sweets\n>>"<<UNITS;
cin>>SWEETS;
cout<<"Price for 1 kg of cookies\n>>"<<UNITS;
cin>>COOKIES;
cout<<"Price for 1 kg of apples\n>>"<<UNITS;
cin>>APPLES;
int x, y, z;
cout<<"Enter amount in kg\n";
cout<<"How many sweets?\n>>";
cin>>x;
cout<<"How many cookies?\n>>";
cin>>y;
cout<<"How many apples?\n>>";
cin>>z;
int total = x*SWEETS + y*COOKIES + z*APPLES;
cout<<"\n"<<"TOTAL PRICE IS\n"<<UNITS<<total<<"\n\n";
return 0;
}