t | import re | t | import re |
| | | |
| | | |
| def process_n(n): | | def process_n(n): |
| names = [] | | names = [] |
| title = '' | | title = '' |
| printer = '' | | printer = '' |
| f = re.search(r'(^[\d]+\.) ', n) | | f = re.search(r'(^[\d]+\.) ', n) |
| if f: | | if f: |
| n = n[f.end():] | | n = n[f.end():] |
| else: | | else: |
| return False | | return False |
| f = re.search( | | f = re.search( |
| r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+)', | | r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+)', |
| n) | | n) |
| if f: | | if f: |
| names.append(f.group()) | | names.append(f.group()) |
| n = n[f.end():] | | n = n[f.end():] |
| else: | | else: |
| return False | | return False |
| f = re.match(r'(,) | (and) | (et al)\., ', n) | | f = re.match(r'(,) | (and) | (et al)\., ', n) |
| if not f: | | if not f: |
| return False | | return False |
| elif f.group() == ' and ': | | elif f.group() == ' and ': |
| n = n[5:] | | n = n[5:] |
| f = re.search( | | f = re.search( |
| r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+), (.*) \((.*)\), [\d\-–]+\.$', | | r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+), (.*) \((.*)\), [\d\-–]+\.$', |
| n) | | n) |
| if not f: | | if not f: |
| return False | | return False |
| names.append(f.groups()[0]) | | names.append(f.groups()[0]) |
| title = f.groups()[1] | | title = f.groups()[1] |
| printer = f.groups()[2] | | printer = f.groups()[2] |
| elif f.group() == ' et al., ': | | elif f.group() == ' et al., ': |
| n = n[f.end():] | | n = n[f.end():] |
| names.append('any') | | names.append('any') |
| f = re.search(r'(.*) \((.*)\), [\d\-–]+\.$', n) | | f = re.search(r'(.*) \((.*)\), [\d\-–]+\.$', n) |
| if not f: | | if not f: |
| return False | | return False |
| title = f.groups()[0] | | title = f.groups()[0] |
| printer = f.groups()[1] | | printer = f.groups()[1] |
| else: | | else: |
| n = n[2:] | | n = n[2:] |
| v = re.search( | | v = re.search( |
| r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+),? and ((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+)', | | r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+),? and ((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+)', |
| n) | | n) |
| if v: | | if v: |
| f = re.search( | | f = re.search( |
| r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+),? and ' | | r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+),? and ' |
| r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+), (.*) \((.*)\), [\d\-–]+\.$', n) | | r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+), (.*) \((.*)\), [\d\-–]+\.$', n) |
| if not f: | | if not f: |
| return False | | return False |
| names.append(f.groups()[0]) | | names.append(f.groups()[0]) |
| names.append(f.groups()[1]) | | names.append(f.groups()[1]) |
| title = f.groups()[2] | | title = f.groups()[2] |
| printer = f.groups()[3] | | printer = f.groups()[3] |
| else: | | else: |
| f = re.search(r'(.*) \((.*)\), [\d\-–]+\.$', n) | | f = re.search(r'(.*) \((.*)\), [\d\-–]+\.$', n) |
| if not f: | | if not f: |
| return False | | return False |
| title = f.groups()[0] | | title = f.groups()[0] |
| printer = f.groups()[1] | | printer = f.groups()[1] |
| return [names, title, printer] | | return [names, title, printer] |
| | | |
| | | |
| def process_b(b): | | def process_b(b): |
| names = [] | | names = [] |
| title = '' | | title = '' |
| printer = '' | | printer = '' |
| f = re.search( | | f = re.search( |
| r'([A-Z][A-Za-z\-]+, (?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)?)', | | r'([A-Z][A-Za-z\-]+, (?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)?)', |
| b) | | b) |
| if not f: | | if not f: |
| return False | | return False |
| names.append(f.group()) | | names.append(f.group()) |
| b = b[f.end():] | | b = b[f.end():] |
| f = re.match(r'( )|(\. )|(, and )|(, )', b) | | f = re.match(r'( )|(\. )|(, and )|(, )', b) |
| if not f: | | if not f: |
| return False | | return False |
| | | |
| if f.group() == ', ' or f.group() == ', and ': | | if f.group() == ', ' or f.group() == ', and ': |
| while f.group() == ', ': | | while f.group() == ', ': |
| b = b[2:] | | b = b[2:] |
| f = re.search( | | f = re.search( |
| r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+)', b) | | r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+)', b) |
| if not f: | | if not f: |
| return False | | return False |
| names.append(f.group()) | | names.append(f.group()) |
| b = b[f.end():] | | b = b[f.end():] |
| f = re.match(r'(, and )|(, )', b) | | f = re.match(r'(, and )|(, )', b) |
| if not f: | | if not f: |
| return False | | return False |
| | | |
| b = b[f.end():] | | b = b[f.end():] |
| f = re.search( | | f = re.search( |
| r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+)\. ', b) | | r'((?:[A-Z]\.|[A-Za-z]+)(?: ?[A-Z]\.| ?[A-Z][a-z]+)? [A-Z][A-Za-z\-]+)\. ', b) |
| if not f: | | if not f: |
| return False | | return False |
| names.append(f.groups()[0]) | | names.append(f.groups()[0]) |
| | | |
| b = b[f.end():] | | b = b[f.end():] |
| f = re.search(r'(.*)\. (.*)\.', b) | | f = re.search(r'(.*)\. (.*)\.', b) |
| if not f: | | if not f: |
| return False | | return False |
| title = f.groups()[0] | | title = f.groups()[0] |
| printer = f.groups()[1] | | printer = f.groups()[1] |
| return [names, title, printer] | | return [names, title, printer] |
| | | |
| | | |
| def compare(n, b): | | def compare(n, b): |
| names1, title1, printer1 = n | | names1, title1, printer1 = n |
| names2, title2, printer2 = b | | names2, title2, printer2 = b |
| if title1 != title2 or printer1 != printer2: | | if title1 != title2 or printer1 != printer2: |
| return False | | return False |
| k = names2[0].split(', ') | | k = names2[0].split(', ') |
| g = k[0] | | g = k[0] |
| k[0] = k[1] | | k[0] = k[1] |
| k[1] = g | | k[1] = g |
| names2[0] = ' '.join(k) | | names2[0] = ' '.join(k) |
| if len(names1) > 1 and names1[1] == 'any': | | if len(names1) > 1 and names1[1] == 'any': |
| if len(names2) < 4: | | if len(names2) < 4: |
| return False | | return False |
| return names1[0] == names2[0] | | return names1[0] == names2[0] |
| return names1 == names2 | | return names1 == names2 |
| | | |
| | | |
| N = input() | | N = input() |
| B = input() | | B = input() |
| n = process_n(N) | | n = process_n(N) |
| b = process_b(B) | | b = process_b(B) |
| if not n or not b: | | if not n or not b: |
| print(False) | | print(False) |
| else: | | else: |
| print(compare(n, b)) | | print(compare(n, b)) |
| | | |