Problem:


西暦和暦変換

西暦で表された年月日を、元号を用いた和暦に変換し、その年月日を出力するプログラムを作成してください。入力は例に示すように 3 つの整数であり、順に西暦年、月、日です。これを、出力例に示すように変換してください。なお、明治以前の年月日が入力された場合は「pre-meiji」と表示してください。

各年号の最初の年は「元年」ではなく「１年」と出力することとします。

元号期間

meiji1868. 9. 8	〜	1912. 7.29

taisho1912. 7.30	〜	1926.12.24

showa1926.12.25	〜	1989. 1. 7

heisei1989. 1. 8	〜

入力

複数のデータが与えられます。各データとして年、月、日を表す３つの整数が空白区切りで１行に与えられます。

 入力の終わりまで処理してください。データの数は 50 を超えません。

出力

空白区切りの元号、年、月、日、または「pre-meiji」を１行に出力してください。

Sample Input

2005 9 3
1868 12 2
1868 9 7

Output for the Sample Input

heisei 17 9 3
meiji 1 12 2
pre-meiji



Sample input:
2005 9 3
1868 12 2
1868 9 7


Sample output:
heisei 17 9 3
meiji 1 12 2
pre-meiji

Submission status: Wrong Answer

Solution code:
import sys
from datetime import timedelta,date

for s in sys.stdin:
    y,m,d = map(int,s.split())
    d = date(y,m,d)
    lis = [
    [date(1989,1,8),"heisei"],
    [date(1926,12,25),"showa"],
    [date(1912,7,30),"taisho"],
    [date(1868,9,8),"meiji"]
    ]
    for e in lis:
        if d > e[0]:
            print e[1],
            print d.year-e[0].year + 1,
            print d.month,
            print d.day
            break
    else:
        print "pre-meiji"

Submission status: Wrong Answer

Solution code:
while 1:
#n=int(raw_input())
    try:
        y,m,d=map(int,raw_input().split())
        if (y<=1868 and m<=9 and d<8) or (y<=1868 and m<=8) or y<=1867:
            print 'pre-meiji'
        elif (y<=1912 and m<=7 and d<30) or (y<=1912 and m<=6) or y<=1911:
            print 'meiji',y-1867,m,d
        elif (y<=1926 and m<=12 and d<25) or (y<=1926 and m<=11) or y<=1925:
            print 'taisho',y-1911,m,d
        elif (y<=1989 and m<=1 and d<7) or y<=1988:
            print 'showa',y-1925,m,d
        else:
            print 'heisei',y-1988,m,d
    except:
        break

Submission status: Wrong Answer

Solution code:
def solve(y,m,d):
	if y<1868 or (y==1868 and m<9) or (y==1868 and m==9 and d<8):
		print("pre-meiji")
	elif 1869<y<1912 or (y==1868 and 7<m) or (y==1868 and m==9 and 8<=d) or (y==1912 and m<7) or(y==1912 and m==7 and d<=29):
		print("meiji %d %d %d"%(y-1868+1,m,d))
	elif 1913<y<1925 or (y==1912 and 7<m) or (y==1912 and m==7 and 25<=d) or (y==1926 and m<12) or (y==1926 and m==12 and d<=24):
		print("taisho %d %d %d"%(y-1912+1,m,d))
	elif 1927<y<1989 or (y==1926 and 12<m) or (y==1926 and m==12 and 25<=d) or (y==1989 and m<1) or (y==1989 and m==1 and d<=7):
		print("showa %d %d %d"%(y-1026+1,m,d))	
	else:
		print("heisei %d %d %d"%(y-1989+1,m,d))


while True:
	try:
		y,m,d=map(int,input().split())
		solve(y,m,d)
	except EOFError:
		break

Submission status: Wrong Answer

Solution code:
def solve(y,m,d):
	if y<1868 or (y==1868 and m<9) or (y==1868 and m==9 and d<8):
		print("pre-meiji")
	elif 1868<y<1912 or (y==1868 and 7<m) or (y==1868 and m==9 and 8<=d) or (y==1912 and m<7) or(y==1912 and m==7 and d<=29):
		print("meiji %d %d %d"%(y-1868+1,m,d))
	elif 1912<y<1926 or (y==1912 and 7<m) or (y==1912 and m==7 and 25<=d) or (y==1926 and m<12) or (y==1926 and m==12 and d<=24):
		print("taisho %d %d %d"%(y-1912+1,m,d))
	elif 1926<y<1989 or (y==1926 and 12<m) or (y==1926 and m==12 and 25<=d) or (y==1989 and m<1) or (y==1989 and m==1 and d<=7):
		print("showa %d %d %d"%(y-1026+1,m,d))	
	else:
		print("heisei %d %d %d"%(y-1989+1,m,d))


while True:
	try:
		y,m,d=map(int,input().split())
		solve(y,m,d)
	except EOFError:
		break

Submission status: Wrong Answer

Solution code:
def solve(y,m,d):
	if y<1868 or (y==1868 and m<9) or (y==1868 and m==9 and d<8):
		print("pre-meiji")
	elif 1868<y<1912 or (y==1868 and 9<m) or (y==1868 and m==9 and 8<=d) or (y==1912 and m<7) or(y==1912 and m==7 and d<=29):
		print("meiji %d %d %d"%(y-1868+1,m,d))
	elif 1912<y<1926 or (y==1912 and 7<m) or (y==1912 and m==7 and 30<=d) or (y==1926 and m<12) or (y==1926 and m==12 and d<=24):
		print("taisho %d %d %d"%(y-1912+1,m,d))
	elif 1926<y<1989 or (y==1926 and 12<m) or (y==1926 and m==12 and 25<=d) or (y==1989 and m<1) or (y==1989 and m==1 and d<=7):
		print("showa %d %d %d"%(y-1026+1,m,d))	
	else:
		print("heisei %d %d %d"%(y-1989+1,m,d))


while True:
	try:
		y,m,d=map(int,input().split())
		solve(y,m,d)
	except EOFError:
		break

Submission status: Wrong Answer

Solution code:
def solve(y,m,d):
	if y<1868 or (y==1868 and m<9) or (y==1868 and m==9 and d<8) or (y==1868 and m<9) or (y==1868 and m==9 and d<8):
		print("pre-meiji")
	elif 1868<y<1912 or (y==1868 and 9<m) or (y==1868 and m==9 and 8<=d) or (y==1912 and m<7) or(y==1912 and m==7 and d<=29):
		print("meiji %d %d %d"%(y-1868+1,m,d))
	elif 1912<y<1926 or (y==1912 and 7<m) or (y==1912 and m==7 and 30<=d) or (y==1926 and m<12) or (y==1926 and m==12 and d<=24):
		print("taisho %d %d %d"%(y-1912+1,m,d))
	elif 1926<y<1989 or (y==1926 and 12<m) or (y==1926 and m==12 and 25<=d) or (y==1989 and m<1) or (y==1989 and m==1 and d<=7):
		print("showa %d %d %d"%(y-1026+1,m,d))	
	else:
		print("heisei %d %d %d"%(y-1989+1,m,d))


while True:
	try:
		y,m,d=map(int,input().split())
		solve(y,m,d)
	except EOFError:
		break

Submission status: Wrong Answer

Solution code:
while True:
    try:
        a, b, c = map(int, input().split())
        if a < 1869 and b < 10 and c < 8:
            print("pre-meiji")
        elif a < 1912 or (a==1912 and b<8 and c<30):
            print("meiji %d %d %d" % (a-1867, b, c))
        elif a < 1927 and c < 25:
            print("taisho %d %d %d" % (a-1911, b, c))
        elif a < 1990 and b < 2 and c < 8:
            print("showa %d %d %d" % (a-1925, b, c))
        else:
            print("heisei %d %d %d" % (a-1988, b, c))
    except:
        break

Submission status: Wrong Answer

Solution code:
from datetime import datetime
def era(f):
    meiji_st  = datetime(1868, 9, 8)
    taisho_st = datetime(1912, 7,30)
    showa_st  = datetime(1926,12,25)
    heisei_st = datetime(1989, 1, 8)

    y,m,d = f
    dt = datetime(y,m,d)
    if dt > heisei_st:
        ret = "heisei %d %d %d" % (dt.year - heisei_st.year+1,dt.month,dt.day) 
    elif dt > showa_st:
        ret = "showa %d %d %d" % (dt.year - showa_st.year+1,dt.month,dt.day) 
    elif dt > taisho_st:
        ret = "taisho %d %d %d" % (dt.year - taisho_st.year+1,dt.month,dt.day) 
    elif dt > meiji_st:
        ret = "meiji %d %d %d" % (dt.year - meiji_st.year+1,dt.month,dt.day) 
    else:
       ret = "pre-meiji"

    return(ret)

while True:
    try:
        f = map(int, input().strip().split())
        print(era(f))
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0083
"""
import sys
import datetime


def solve(yyyy, mm, dd):
    d = datetime.datetime(yyyy, mm, dd)
    meiji_start = datetime.datetime(1868, 9, 8)
    taisho_start = datetime.datetime(1912, 1, 1)
    showa_start = datetime.datetime(1926, 1,1 )
    heisei_start = datetime.datetime(1989, 1,1 )

    result = 'not initialized'
    if d < meiji_start:
        result = 'pre-meiji'
    elif d < taisho_start:
        result = 'meiji {} {} {}'.format(d.year-meiji_start.year+1, mm, dd)
    elif d < showa_start:
        result = 'taisho {} {} {}'.format(d.year-taisho_start.year+1, mm, dd)
    elif d < heisei_start:
        result = 'showa {} {} {}'.format(d.year-showa_start.year+1, mm, dd)
    else:
        result = 'heisei {} {} {}'.format(d.year-heisei_start.year+1, mm, dd)
    return result


def main(args):
    for line in sys.stdin:
        yyyy, mm, dd = [int(x) for x in line.strip().split(' ')]
        result = solve(yyyy, mm, dd)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# Aizu Problem 0083: Era Transformation
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def era_transformation(y, m, d):
    if int(m) < 10:
        m = '0' + m
    if int(d) < 10:
        d = '0' + d
    date = int(y + m + d)
    y = int(y)
    m = int(m)
    d = int(d)
    if date < 18680908:
        print("pre-meiji")
        return
    elif date <= 19120729:
        print("meiji", y - 1868 + 1, m, d)
    elif date <= 19261224:
        print("taisho", y - 1926 + 1, m, d)
    elif date <= 19890107:
        print("showa", y - 1989 + 1, m, d)
    else:
        print("heisei", y - 1989 + 1, m, d)

    
for line in sys.stdin:
    y, m, d = line.split()
    era_transformation(y, m, d)

Submission status: Wrong Answer

Solution code:
import sys
p=["pre-meiji","meiji","taisho","showa","heisei"]
q=[0,18680908,19120730,19261225,19890101,99999999]
for line in sys.stdin.readlines():
    y,m,d=map(int,line.strip().split())
    t=y*10000+m*100+d
    i=0
    while not (q[i]<=t<q[i+1]):
        i+=1
    if i==0:print p[i]
    else:print p[i],y-q[i]/10000+1,m,d

Submission status: Wrong Answer

Solution code:
ans=[]
while True:
    try:
        year,month,day=map(int,raw_input().split())
    except EOFError:
        break
    except ValueError:
        break
    wareki=''
    if (year < 1868) or (year == 1868 and month < 9) or (year == 1868 and month == 9 and day <= 7):
        ans.append('pre-meiji')
        continue
    elif (year < 1912) or (year == 1912 and month < 7) or (year == 1912 and month == 7 and day <= 29):
        wareki+='meiji '+str(year-1867)
    elif (year < 1926) or (year == 1926 and month < 12) or (year == 1926 and month == 12 and day <= 24):
        wareki+='taisho '+str(year-1911)
    elif (year < 1989) or (year == 1989 and month < 1) or (year == 1989 and month == 1 and day <= 7):
        wareki+='taisho '+str(year-1925)
    else:
        wareki+='heisei '+str(year-1988)
    ans.append(wareki+' '+str(month)+' '+str(day))
for i in ans:
    print i

Submission status: Wrong Answer

Solution code:
while True:
    try:

        a,b,c = map(int,raw_input().split(" "))


        if a >= 1990:
            a = a - 1989 +1
            print "heisei",a,b,c
        elif a == 1989:
            if b == 1:
                if c >= 8:
                    a = a - 1989 + 1
                    print "heisei",a,b,c,
                else:
                    a = a - 1926 + 1
                    print "showa",a,b,c
            else:
                a = a - 1989 +1
                print "heisei",a,b,c

        elif a >= 1927 :
            a = a - 1926 + 1
            print "showa",a,b,c
        elif a == 1926:
            if b == 12:
                if c >= 25:
                    a = a - 1926 + 1
                    print "showa",a,b,c
                else:
                    a = a - 1912 +1
                    print "taisho",a,b,c
            else:

                a = a - 1912 +1
                print "taisho",a,b,c

        elif a > 1913:
            a = a - 1912 + 1
            print "taisho",a,b,c
        elif a == 1912:
            if b == 7:
                if c >= 30:
                    a = a - 1912 + 1
                    print "taisho",a,b,c
                else:
                    a = a - 1868 + 1
                    print "meiji",a,b,c
            elif b > 7:
                a = a - 1912 + 1
                print "taisho",a,b,c

            else:
                a = a - 1868 + 1
                print "meiji",a,b,c

        elif a >= 1869:
            a = a -  1868 + 1
            print "meiji",a,b,c
        elif a == 1868:
            if b == 9:
                if c >= 8:
                    a = a- 1868 +1
                    print "meiji",a,b,c
                else:
                    print "pre-meiji"
            elif b > 9:
                a = a - 1868 + 1
                print "meiji",a,b,c
            else:
                print "pre-meiji"
        else:
            print "pre-meiji"


    except EOFError :
        break

Submission status: Wrong Answer

Solution code:
while True:
	try:
		y, m, d = map(int, raw_input().split())
		date = int("{}{}{}".format(y,'%02d'%m,'%02d'%d))
		if date < 18680908:
			print "pre-meiji"
		elif date < 19210729:
			y = y - 1868 + 1
			print "meiji {} {} {}".format(y,m,d)
		elif date < 19261224:
			y = y - 1912 + 1
			print "taisho {} {} {}".format(y,m,d)
		elif date < 19890107:
			y = y - 1926 + 1
			print "showa {} {} {}".format(y,m,d)
		else:
			y = y - 1989 + 1
			print "heisei {} {} {}".format(y,m,d)
	except:
		break

Submission status: Wrong Answer

Solution code:
while True:
	try:
		y, m, d = map(int, raw_input().split())
		date = int("{}{}{}".format('%04d'%y,'%02d'%m,'%02d'%d))
		if date < 18680908:
			print "pre-meiji"
		elif date < 19210729:
			y = y - 1868 + 1
			print "meiji {} {} {}".format(y,m,d)
		elif date < 19261224:
			y = y - 1912 + 1
			print "taisho {} {} {}".format(y,m,d)
		elif date < 19890107:
			y = y - 1926 + 1
			print "showa {} {} {}".format(y,m,d)
		else:
			y = y - 1989 + 1
			print "heisei {} {} {}".format(y,m,d)
	except:
		break

Submission status: Wrong Answer

Solution code:
while True:
	try:
		y, m, d = map(int, raw_input().split())
		date = int("{}{}{}".format('%04d'%y,'%02d'%m,'%02d'%d))
		if date < 18680908:
			print "pre-meiji"
		elif date < 19210730:
			y = y - 1868 + 1
			print "meiji {} {} {}".format(y,m,d)
		elif date < 19261225:
			y = y - 1912 + 1
			print "taisho {} {} {}".format(y,m,d)
		elif date < 19890108:
			y = y - 1926 + 1
			print "showa {} {} {}".format(y,m,d)
		else:
			y = y - 1989 + 1
			print "heisei {} {} {}".format(y,m,d)
	except:
		break

Submission status: Accepted

Solution code:
m_ = [31,28,31,30,31,30,31,31,30,31,30,31]
m_sum = [0]
m_sum.extend([sum(m_[0:i+1]) for i in range(12)])
def mtod(m,d):
    s = m_sum[m-1] + d
    return s
def dtom(s):
    for i in range(13):
        if s < m_sum[i]:
            return i,s - m_sum[i-1]

def minus(a,b):
    if a >= b:
        return a-b
    else:
        return a + 365 - b
    
meiji = 1000*1868 + mtod(9,8)
taisho = 1000*1912 + mtod(7,30)
showa = 1000*1926 + mtod(12,25)
heisei = 1000*1989 + mtod(1,8)

while(1):
    try:
        y,m,d = [int(i) for i in input().split()]
        s = 1000*y + mtod(m,d)
        if s < meiji:
            print("pre-meiji")
        elif s < taisho:
            print("meiji", int(s/1000) -int(meiji/1000) + 1, m ,d)
        elif s < showa:
            print("taisho", int(s/1000) -int(taisho/1000) + 1, m,d)
        elif s < heisei:
            print("showa", int(s/1000) -int(showa/1000) + 1, m,d)
        else:
            print("heisei", int(s/1000) -int(heisei/1000) + 1, m,d)
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
from datetime import timedelta,date

for s in sys.stdin:
    y,m,d = map(int,s.split())
    d = date(y,m,d)
    lis = [
    [date(1989,1,8),"heisei"],
    [date(1926,12,25),"showa"],
    [date(1912,7,30),"taisho"],
    [date(1868,9,8),"meiji"]
    ]
    for e in lis:
        if d >= e[0]:
            print e[1],
            print d.year-e[0].year + 1,
            print d.month,
            print d.day
            break
    else:
        print "pre-meiji"

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

from datetime import date

eras = {'pre-meiji':{'start':None, 'end':date(1868,9,7)},
'meiji':{'start':date(1868, 9, 8), 'end':date(1912,7,29)},
'taisho':{'start':date(1912, 7, 30), 'end':date(1926,12,24)},
'showa':{'start':date(1926, 12, 25), 'end':date(1989,1,7)},
'heisei':{'start':date(1989, 1, 8), 'end':None}}

for line in f:
    y, m, d = map(int, line.split())
    target = date(y,m,d)
    for era_name, period in eras.items():
        if (period['start'] is None or period['start'] <= target) and(period['end'] is None or target <= period['end']):
            if era_name == 'pre-meiji':
                print(era_name)
            else:
                print(era_name, target.year - period['start'].year + 1, target.month, target.day)
            break

Submission status: Accepted

Solution code:
import sys

for line in sys.stdin:
    y, m, d = map(int, line.rstrip().split())
    if (1989 == y and 1 == m and 8 <= d) or (1989 == y and 2 <= m) or 1990 <= y:
        print 'heisei %s %s %s' % (y-1989+1, m, d)
    elif (1926 == y and 12 == m and 25 <= d) or (1927 <= y <= 1989):
        print 'showa %s %s %s' % (y-1926+1, m, d)
    elif (1912 == y and 7 == m and 30 <= d) or (1912 == y and 8 <= m) or (1913 <= y <= 1926):
        print 'taisho %s %s %s' % (y-1912+1, m, d)
    elif (1868 == y and 9 == m and 8 <= d) or (1868 == y and 10 <= m) or (1869 <= y <= 1912):
        print 'meiji %s %s %s' % (y-1868+1, m, d)
    else:
        print 'pre-meiji'

Submission status: Accepted

Solution code:
def doc_string():
	"""
	I can fly.
	"""

while True:
	try:
		a,b,c = map(str,raw_input().split())
	except EOFError:
		break
	
	if len(b) == 1:
		b = "0" + b
	if len(c) == 1:
		c = "0" + c
		
	code = int(a + b + c)
	
	if code >= 19890108:
		print "heisei",int(a) - 1989 + 1,int(b),int(c)
	elif 19261225 <= code and code <= 19890107:
		print "showa",int(a) - 1926 + 1,int(b),int(c)
	elif 19120730 <= code and code <= 19261224:
		print "taisho",int(a) - 1912 + 1,int(b),int(c)
	elif 18680908 <= code and code <= 19120729:
		print "meiji",int(a) - 1868 + 1,int(b),int(c)
	else:
		print "pre-meiji"

Submission status: Accepted

Solution code:
while 1:
#n=int(raw_input())
    try:
        y,m,d=map(int,raw_input().split())
        if (y<=1868 and m<=9 and d<8) or (y<=1868 and m<=8) or y<=1867:
            print 'pre-meiji'
        elif (y<=1912 and m<=7 and d<30) or (y<=1912 and m<=6) or y<=1911:
            print 'meiji',y-1867,m,d
        elif (y<=1926 and m<=12 and d<25) or (y<=1926 and m<=11) or y<=1925:
            print 'taisho',y-1911,m,d
        elif (y<=1989 and m<=1 and d<8) or y<=1988:
            print 'showa',y-1925,m,d
        else:
            print 'heisei',y-1988,m,d
    except:
        break

Submission status: Accepted

Solution code:
def solve(y,m,d):
	if y<1868 or (y==1868 and m<9) or (y==1868 and m==9 and d<8):
		print("pre-meiji")
	elif 1868<y<1912 or (y==1868 and 9<m) or (y==1868 and m==9 and 8<=d) or (y==1912 and m<7) or(y==1912 and m==7 and d<=29):
		print("meiji %d %d %d"%(y-1868+1,m,d))
	elif 1912<y<1926 or (y==1912 and 7<m) or (y==1912 and m==7 and 30<=d) or (y==1926 and m<12) or (y==1926 and m==12 and d<=24):
		print("taisho %d %d %d"%(y-1912+1,m,d))
	elif 1926<y<1989 or (y==1926 and 12<m) or (y==1926 and m==12 and 25<=d) or (y==1989 and m<1) or (y==1989 and m==1 and d<=7):
		print("showa %d %d %d"%(y-1926+1,m,d))	
	else:
		print("heisei %d %d %d"%(y-1989+1,m,d))


while True:
	try:
		y,m,d=map(int,input().split())
		solve(y,m,d)
	except EOFError:
		break

Submission status: Accepted

Solution code:
while True:
    try:
        y,m,d = map(int,input().split())
        if y < 1868 or (y == 1868 and m < 9):
            print("pre-meiji")
        elif y == 1868 and m == 9 and d < 8:
            print("pre-meiji")
        elif y < 1912 or (y == 1926 and m < 7):
            print("meiji",y - 1868 + 1,m,d)
        elif y == 1912 and m == 7 and d < 30:
            print("meiji",y - 1868 + 1,m,d)
        elif y < 1926 or (y == 1926 and m < 12):
            print("taisho",y - 1912 + 1,m,d)
        elif y == 1926 and m ==12 and d < 25:
            print("taisho",y - 1912 + 1,m,d)
        elif y <1989 or (y == 1989 and m == 1 and d < 8):
            print("showa",y - 1926 + 1,m,d)
        else:
            print("heisei",y - 1989 + 1,m,d)
    except EOFError:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        a, b, c = map(int, input().split())
    except:
        break

    if a < 1868 or (a==1868 and b<10 and c<8):
        print("pre-meiji")
    elif a < 1912 or (a==1912 and b<8 and c<30):
        print("meiji %d %d %d" % (a-1867, b, c))
    elif a < 1926 or (a==1926 and c<25):
        print("taisho %d %d %d" % (a-1911, b, c))
    elif a < 1989 or (a==1989 and b<2 and c<8):
        print("showa %d %d %d" % (a-1925, b, c))
    else:
        print("heisei %d %d %d" % (a-1988, b, c))

Submission status: Accepted

Solution code:
from datetime import datetime
while 1:
    try:y,m,d=map(int,input().split())
    except:break
    dt = (datetime(y,m,d)-datetime(1868,9,8)).days
    if dt<0:print('pre-meiji')
    elif dt<16030:print('meiji',y-1867,m,d)
    elif dt<21291:print('taisho',y-1911,m,d)
    elif dt<43951:print('showa',y-1925,m,d)
    else:print('heisei',y-1988,m,d)

Submission status: Accepted

Solution code:
from datetime import datetime
def era(f):
    meiji_st  = datetime(1868, 9, 8)
    taisho_st = datetime(1912, 7,30)
    showa_st  = datetime(1926,12,25)
    heisei_st = datetime(1989, 1, 8)

    y,m,d = f
    dt = datetime(y,m,d)
    if dt >= heisei_st:
        ret = "heisei %d %d %d" % (dt.year - heisei_st.year+1,dt.month,dt.day) 
    elif dt >= showa_st:
        ret = "showa %d %d %d" % (dt.year - showa_st.year+1,dt.month,dt.day) 
    elif dt >= taisho_st:
        ret = "taisho %d %d %d" % (dt.year - taisho_st.year+1,dt.month,dt.day) 
    elif dt >= meiji_st:
        ret = "meiji %d %d %d" % (dt.year - meiji_st.year+1,dt.month,dt.day) 
    else:
       ret = "pre-meiji"

    return(ret)

while True:
    try:
        f = map(int, input().strip().split())
        print(era(f))
    except EOFError:
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

def day_to_num(y, m, d):
    s = "{:04d}{:02d}{:02d}".format(y, m, d)
    return int(s)

for s in sys.stdin:
    y, m, d = list(map(int, s.split()))

    n = day_to_num(y, m, d)

    if n < 18680908:
        gengo = 'pre-meiji'
    elif 18680908 <= n <= 19120729:
        gengo = 'meiji'
        Y = y - 1868 + 1
    elif 19120730 <= n <= 19261224:
        gengo = 'taisho'
        Y = y - 1912 + 1
    elif 19261225 <= n <= 19890107:
        gengo = 'showa'
        Y = y - 1926 + 1
    else:
        Y = y - 1989 + 1
        gengo = 'heisei'

    if gengo == 'pre-meiji':
        print(gengo)
    else:
        print(gengo, Y, m, d)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0083
"""
import sys
import datetime


def solve(yyyy, mm, dd):
    d = datetime.datetime(yyyy, mm, dd)
    meiji_start = datetime.datetime(1868, 9, 8)
    taisho_start = datetime.datetime(1912, 7, 30)
    showa_start = datetime.datetime(1926, 12, 25)
    heisei_start = datetime.datetime(1989, 1, 8)

    result = 'not initialized'
    if d < meiji_start:
        result = 'pre-meiji'
    elif meiji_start <= d < taisho_start:
        result = 'meiji {} {} {}'.format(d.year-meiji_start.year+1, mm, dd)
    elif taisho_start <= d < showa_start:
        result = 'taisho {} {} {}'.format(d.year-taisho_start.year+1, mm, dd)
    elif showa_start <= d < heisei_start:
        result = 'showa {} {} {}'.format(d.year-showa_start.year+1, mm, dd)
    else:
        result = 'heisei {} {} {}'.format(d.year-heisei_start.year+1, mm, dd)
    return result


def main(args):
    for line in sys.stdin:
        yyyy, mm, dd = [int(x) for x in line.strip().split(' ')]
        result = solve(yyyy, mm, dd)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# Aizu Problem 0083: Era Transformation
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def era_transformation(y, m, d):
    if int(m) < 10:
        m = '0' + m
    if int(d) < 10:
        d = '0' + d
    date = int(y + m + d)
    y = int(y)
    m = int(m)
    d = int(d)
    if date < 18680908:
        print("pre-meiji")
        return
    elif date <= 19120729:
        print("meiji", y - 1868 + 1, m, d)
    elif date <= 19261224:
        print("taisho", y - 1912 + 1, m, d)
    elif date <= 19890107:
        print("showa", y - 1926 + 1, m, d)
    else:
        print("heisei", y - 1989 + 1, m, d)

    
for line in sys.stdin:
    y, m, d = line.split()
    era_transformation(y, m, d)

Submission status: Accepted

Solution code:
import datetime

while True:
    try:
        y, m, d = map(int, input().split())
        n = 10000*y + 100*m +d
        if n < 18680908:
            print("pre-meiji")
        elif n < 19120730:
            print("meiji", y - 1867, m, d)
        elif n < 19261225:
            print("taisho", y - 1911, m, d)
        elif n < 19890108:
            print("showa", y - 1925, m, d)
        else:
            print("heisei", y - 1988, m, d)
    except:
        break

Submission status: Accepted

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())

for l in range(len(N)):
    y,m,d = [int(i) for i in N[l].split()]
    id = y * 10000 + m * 100 + d
    if id < 18680908:
        print("pre-meiji")
    elif id < 19120730:
        print("meiji", y - 1867, m, d)
    elif id < 19261225:
        print("taisho", y - 1911, m, d)
    elif id < 19890108:
        print("showa", y - 1925, m, d)
    else:
        print("heisei", y - 1988, m, d)

Submission status: Accepted

Solution code:
import sys
n=[19890107,19261224,19120729,18680907]
for e in sys.stdin:
 y,m,d=map(int,e.split())
 t=y*1e4+m*100+d
 for i in range(4):
  if n[i]<t:print([f'heisei {y-1988}',f'showa {y-1925}',f'taisho {y-1911}',f'meiji {y-1867}'][i],m,d);break
 else:print('pre-meiji')

Submission status: Accepted

Solution code:
from datetime import datetime
while 1:
 try:y,m,d=map(int,input().split())
 except:break
 dt = (datetime(y,m,d)-datetime(1868,9,8)).days
 if dt<0:print('pre-meiji')
 elif dt<16030:print('meiji',y-1867,m,d)
 elif dt<21291:print('taisho',y-1911,m,d)
 elif dt<43951:print('showa',y-1925,m,d)
 else:print('heisei',y-1988,m,d)

Submission status: Accepted

Solution code:
def put_era(day):
  if day < [1868, 9, 8]:
    print("pre-meiji")
  
  elif day <= [1912, 7, 29]:
    print(*["meiji",day[0] - 1868 + 1, day[1], day[2]])
  
  elif day <= [1926, 12, 24]:
    print(*["taisho",day[0] - 1912 + 1, day[1], day[2]])
  
  elif day <= [1989, 1, 7]:
    print(*["showa",day[0] - 1926 + 1, day[1], day[2]])
  
  else:
    print(*["heisei",day[0] - 1989 + 1, day[1], day[2]])

while True:
  try:
    day = list(map(int, input().split()))
    put_era(day)

  except EOFError:
    break

Submission status: Accepted

Solution code:
def put_era(day):
  if day < [1868, 9, 8]:
    print("pre-meiji")
  
  elif day <= [1912, 7, 29]:
    print("meiji",day[0] - 1868 + 1, day[1], day[2])
  
  elif day <= [1926, 12, 24]:
    print("taisho",day[0] - 1912 + 1, day[1], day[2])
  
  elif day <= [1989, 1, 7]:
    print("showa",day[0] - 1926 + 1, day[1], day[2])
  
  else:
    print("heisei",day[0] - 1989 + 1, day[1], day[2])

while True:
  try:
    day = list(map(int, input().split()))
    put_era(day)

  except EOFError:
    break

Submission status: Accepted

Solution code:
# AOJ 0083 Era Name Transformation
# Python3 2018.6.11 bal4u

start_date = [18680908, 19120730, 19261225, 19890108, 99999999]
era = ["pre-meiji", "meiji", "taisho", "showa", "heisei"]

import sys
for line in sys.stdin:
    y, m, d = list(map(int, line.split()))
    date = y*10000 + m*100 + d
    for i in range(5):
        if date < start_date[i]:
            if i is 0:
                print(era[0])
            else:
                print(era[i], date//10000 - start_date[i-1]//10000 + 1, m, d)
            break

Submission status: Accepted

Solution code:
from datetime import date
import sys
for i in sys.stdin:
    y,m,d=list(map(int,i[:-1].split()))
    dt=lambda y,m,d:date(year=y,month=m,day=d)
    nd=dt(y,m,d)

    if nd < dt(1868,9,8):
        print("pre-meiji")
    elif dt(1868,9,8) <= nd <= dt(1912,7,29):
        print("meiji",y-1867,m,d)
    elif dt(1912,7,30) <= nd <= dt(1926,12,24):
        print("taisho",y-1911,m,d)
    elif dt(1926,12,25) <= nd <= dt(1989,1,7):
        print("showa",y-1925,m,d)
    else:
        print("heisei",y-1988,m,d)

Submission status: Accepted

Solution code:
import sys
p=["pre-meiji","meiji","taisho","showa","heisei"]
q=[-999999,18680908,19120730,19261225,19890108,99999999]
for line in sys.stdin.readlines():
    y,m,d=map(int,line.strip().split())
    t=y*10000+m*100+d
    i=0
    while not (q[i]<=t<q[i+1]):
        i+=1
    if i==0:print p[i]
    else:print p[i],y-q[i]/10000+1,m,d

Submission status: Accepted

Solution code:
ans=[]
while True:
    try:
        year,month,day=map(int,raw_input().split())
    except EOFError:
        break
    except ValueError:
        break
    wareki=''
    if (year < 1868) or (year == 1868 and month < 9) or (year == 1868 and month == 9 and day <= 7):
        ans.append('pre-meiji')
        continue
    elif (year < 1912) or (year == 1912 and month < 7) or (year == 1912 and month == 7 and day <= 29):
        wareki+='meiji '+str(year-1867)
    elif (year < 1926) or (year == 1926 and month < 12) or (year == 1926 and month == 12 and day <= 24):
        wareki+='taisho '+str(year-1911)
    elif (year < 1989) or (year == 1989 and month < 1) or (year == 1989 and month == 1 and day <= 7):
        wareki+='showa '+str(year-1925)
    else:
        wareki+='heisei '+str(year-1988)
    ans.append(wareki+' '+str(month)+' '+str(day))
for i in ans:
    print i

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for line in stdin:
    date = tuple(int(s) for s in line.split())
    if date < (1868, 9, 8):
        print('pre-meiji')
    elif date < (1912, 7, 30):
        print('meiji', date[0] - 1867, date[1], date[2])
    elif date < (1926, 12, 25):
        print('taisho', date[0] - 1911, date[1], date[2])
    elif date < (1989, 1, 8):
        print('showa', date[0] - 1925, date[1], date[2])
    else:
        print('heisei', date[0] - 1988, date[1], date[2])

Submission status: Accepted

Solution code:
while True:
    try:
        y, m, d = map(int, raw_input().split())
        ymd = 10000*y + 100*m + d
        if ymd < 18680908:
            print "pre-meiji"
        elif ymd < 19120730:
            print "meiji",y-1867,m,d
        elif ymd < 19261225:
            print "taisho",y-1911,m,d
        elif ymd < 19890108:
            print "showa",y-1925,m,d
        else:
            print "heisei",y-1988,m,d
    except:
        break

Submission status: Accepted

Solution code:
def check(ymd):
        if ymd < 18680908:
            print "pre-meiji"
        elif ymd < 19120730:
            print "meiji",y-1867,m,d
        elif ymd < 19261225:
            print "taisho",y-1911,m,d
        elif ymd < 19890108:
            print "showa",y-1925,m,d
        else:
            print "heisei",y-1988,m,d

while True:
    try:
        y, m, d = map(int, raw_input().split())
        ymd = 10000*y + 100*m + d
        check(ymd)
    except:
        break

Submission status: Accepted

Solution code:
def check(ymd,y,m,d):
        if ymd < 18680908:
            print "pre-meiji"
        elif ymd < 19120730:
            print "meiji",y-1867,m,d
        elif ymd < 19261225:
            print "taisho",y-1911,m,d
        elif ymd < 19890108:
            print "showa",y-1925,m,d
        else:
            print "heisei",y-1988,m,d

while True:
    try:
        y, m, d = map(int, raw_input().split())
        ymd = 10000*y + 100*m + d
        check(ymd,y,m,d)
    except:
        break

Submission status: Accepted

Solution code:
while True:
	try:
		y, m, d = map(int, raw_input().split())
		date = int("{}{}{}".format('%04d'%y,'%02d'%m,'%02d'%d))
		if date < 18680908:
			print "pre-meiji"
		elif date < 19120730:
			y = y - 1868 + 1
			print "meiji {} {} {}".format(y,m,d)
		elif date < 19261225:
			y = y - 1912 + 1
			print "taisho {} {} {}".format(y,m,d)
		elif date < 19890108:
			y = y - 1926 + 1
			print "showa {} {} {}".format(y,m,d)
		else:
			y = y - 1989 + 1
			print "heisei {} {} {}".format(y,m,d)
	except:
		break