Description:给定一组整数,还有一个目标数,在给定这组整数中找到两个数字,使其和为目标数,如找到,解是唯一的。找不到则显示 “no answer”。输出的下标按从小到大排序。用一重循环加字典实现。
Input:在一行中给出这组数。 在下一行输入目标数
Output:输出仅一行,输出这两个数的下标,用一个空格分开。
Sample Input:
2,7,11,15
9
Sample Output:
0 1
Sample Input:
3,6,9
10
Sample Output:
no answer
a = list(map(int, input().split(',')))
b = int(input())
t = False
for i in range(len(a)):
for j in range(len(a)):
if a[i] + a[j] == b:
print(i, j)
t = True
break
if t:
break
if t == False:
print("no answer")