1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
import sys from collections import defaultdict
for line in sys.stdin: line = line.strip() if not line: continue line_list = line.split(" ")
numbers=defaultdict(int) for index,word in enumerate(line_list): if word.isdigit(): numbers[index] = word
if not numbers: print(line) continue
max_index = max(numbers.keys()) min_index = min(numbers.keys())
line_list[max_index],line_list[min_index] = line_list[min_index],line_list[max_index] print(" ".join(line_list))
|