Ant book in python: page 45 Dictionary order minimum problem (POJ3617)


# coding: utf-8
import copy
input_S =list(raw_input())
T = ""
reversed_S = copy.deepcopy(input_S)

reversed_S.reverse()

while(len(input_S)> 0):
    if input_S < reversed_S:
        T += input_S[0]
        input_S = input_S[1:]
        reversed_S= reversed_S[:-1]

    else:
        T += reversed_S[0]
        input_S = input_S[:-1]
        reversed_S= reversed_S[1:]
print T

It was unusual (for me) to write simpler than the answer example.

Recommended Posts

Ant book in python: page 45 Dictionary order minimum problem (POJ3617)
Ant book in python: page 47 Saruman's Army (POJ 3069)
Ant book in python: page 43 Interval scheduling
Ant book in python: page 49 Fence Repair
Ant book in python: Sec. 2-5 Graph
Ant book in python: Priority queue self-implementation
Ant book in python: Sec. 2-4, data structures
Ant book in python: Sec.2-5 Dijkstra's algorithm
Ant book in python: Sec. 2-5 Graph (preparation)
Ant book in python: Sec. 2-3, Dynamic Programming (DP)
Natural order in python
Create a dictionary in Python
Avoid KeyError in python dictionary
[Note] Project Euler in Python (Problem 1-22)
Project Euler # 5 "Minimum Multiples" in Python
ABC166 in Python A ~ C problem
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Page cache in Python + Flask with Flask-Caching
Ant book with python (chapter3 intermediate edition ~)
Python / dictionary> setdefault ()> Add if not in dictionary
Hash in Perl is a dictionary in Python
Solve the maximum subarray problem in Python