Problem Statement
In algebra, a presentation is a convenient way to describe a set. The presentation includes what the atomic elements of the set are, and what relations are used to simplify strings of atoms. These atoms are usually called generators. In this problem we will be looking at a set whose generators are x and y. You will be given a String expression consisting of x's and y's. The simplifying rules are:
- 1) Any occurrence of yyyyyy can be deleted from the string.
- 2) Any occurrence of xxxxxxxx can be deleted from the string.
- 3) Any occurrence of xy can be replaced by yyyyyx.
Definition
- Class:
- PresentationComp
- Method:
- simplify
- Parameters:
- String
- Returns:
- String
- Method signature:
- String simplify(String expression)
- (be sure your method is public)
Constraints
- expression will contain between 1 and 50 characters inclusive.
- Each character in expression will be x or y.
Examples
"xxxxxxxxyyyyyy"
Returns: ""
Simplifies greatly."xy"
Returns: "xy"
Doesn't get much simpler."yyxx"
Returns: "xxyy"
Use the one that comes first alphabetically.