t | from fractions import Fraction | t | from fractions import Fraction |
| | | |
| class Sausage: | | class Sausage: |
| length = 12 | | length = 12 |
| start = '/------------\\' | | start = '/------------\\' |
| stop = '\\------------/' | | stop = '\\------------/' |
| line = [] | | line = [] |
| | | |
| def __init__(self=None): | | def __init__(self=None): |
| return None | | return None |
| | | |
| def __init__(self, meat='pork!', v=1.0): | | def __init__(self, meat='pork!', v=1.0): |
| if Fraction(v) <= Fraction(0): | | if Fraction(v) <= Fraction(0): |
| self.volume = 0 | | self.volume = 0 |
| self.meat = '' | | self.meat = '' |
| else: | | else: |
| self.meat = meat | | self.meat = meat |
| self.volume = Fraction(v) | | self.volume = Fraction(v) |
| self.line = [] | | self.line = [] |
| | | |
| def __bool__(self): | | def __bool__(self): |
| if self.volume == 0: | | if self.volume == 0: |
| return False | | return False |
| return True | | return True |
| | | |
| def getlines(self): | | def getlines(self): |
| n = int(12 * Fraction(self.volume)) | | n = int(12 * Fraction(self.volume)) |
| m = 2 * (int(self.volume * 12) % 12 + int(self.volume * 12) // 12) | | m = 2 * (int(self.volume * 12) % 12 + int(self.volume * 12) // 12) |
| self.start = '/------------'[:n + 1] + ('|' if n + 2 < 13 else '\\') | | self.start = '/------------'[:n + 1] + ('|' if n + 2 < 13 else '\\') |
| self.stop = '\\------------'[:n + 1] + ('|' if n + 2 < 13 else '/') | | self.stop = '\\------------'[:n + 1] + ('|' if n + 2 < 13 else '/') |
| self.line.append('|') | | self.line.append('|') |
| (j, k) = (0, 0) | | (j, k) = (0, 0) |
| for (m, i) in enumerate(range(n)): | | for (m, i) in enumerate(range(n)): |
| if i != 0 and i % 12 == 0: | | if i != 0 and i % 12 == 0: |
| self.line.append('|') | | self.line.append('|') |
| self.line.append('|') | | self.line.append('|') |
| if n >= i + 24: | | if n >= i + 24: |
| self.start += self.__class__.start | | self.start += self.__class__.start |
| self.stop += self.__class__.stop | | self.stop += self.__class__.stop |
| else: | | else: |
| if len(self.start) > n + n / 12 * 2: | | if len(self.start) > n + n / 12 * 2: |
| continue | | continue |
| self.start += '/------------'[:n - i + 1] + ('|' if n - i < 12 else '\\') | | self.start += '/------------'[:n - i + 1] + ('|' if n - i < 12 else '\\') |
| self.stop += '\\------------'[:n - i + 1] + ('|' if n - i < 12 else '/') | | self.stop += '\\------------'[:n - i + 1] + ('|' if n - i < 12 else '/') |
| j = 0 | | j = 0 |
| self.line.append(self.meat[j]) | | self.line.append(self.meat[j]) |
| if j < len(self.meat) - 1: | | if j < len(self.meat) - 1: |
| j += 1 | | j += 1 |
| else: | | else: |
| j = 0 | | j = 0 |
| self.line.append('|') | | self.line.append('|') |
| | | |
| def __add__(self, other): | | def __add__(self, other): |
| return Sausage(self.meat, self.volume + other.volume) | | return Sausage(self.meat, self.volume + other.volume) |
| | | |
| def __mul__(self, other): | | def __mul__(self, other): |
| return Sausage(self.meat, self.volume * Fraction(other)) | | return Sausage(self.meat, self.volume * Fraction(other)) |
| | | |
| def __rmul__(self, other): | | def __rmul__(self, other): |
| return Sausage(self.meat, self.volume * Fraction(other)) | | return Sausage(self.meat, self.volume * Fraction(other)) |
| | | |
| def __truediv__(self, other): | | def __truediv__(self, other): |
| return Sausage(self.meat, self.volume / Fraction(other)) | | return Sausage(self.meat, self.volume / Fraction(other)) |
| | | |
| def __sub__(self, other): | | def __sub__(self, other): |
| return Sausage(self.meat, self.volume - other.volume) | | return Sausage(self.meat, self.volume - other.volume) |
| | | |
| def __abs__(self): | | def __abs__(self): |
| return self.volume | | return self.volume |
| | | |
| def __str__(self): | | def __str__(self): |
| self.getlines() | | self.getlines() |
| return self.start + '\n' + '{0}\n{0}\n{0}\n'.format(''.join(self.line)) + self.stop | | return self.start + '\n' + '{0}\n{0}\n{0}\n'.format(''.join(self.line)) + self.stop |
| import sys | | import sys |
| exec(sys.stdin.read(), globals()) | | exec(sys.stdin.read(), globals()) |