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: Accepted

Solution code:
import sys
for s in sys.stdin:
  y,m,d=map(int,s[:-1].split())
  x="%d%02d%02d"%(y,m,d)
  if x<"18680908":e="pre-meiji"
  elif x<"19120730":e="meiji %d %d %d"%(y-1867,m,d)
  elif x<"19261225":e="taisho %d %d %d"%(y-1911,m,d)
  elif x<"19890108":e="showa %d %d %d"%(y-1925,m,d)
  else:e="heisei %d %d %d"%(y-1988,m,d)
  print e

Submission status: Accepted

Solution code:
import sys
for s in sys.stdin:
  y,m,d=map(int,s[:-1].split())
  x="%d%02d%02d"%(y,m,d)
  w=" %d %d"%(m,d)
  if x<"18680908":e="pre-meiji"
  elif x<"19120730":e="meiji %d"%(y-1867)+w
  elif x<"19261225":e="taisho %d"%(y-1911)+w
  elif x<"19890108":e="showa %d"%(y-1925)+w
  else:e="heisei %d"%(y-1988)+w
  print e

Submission status: Accepted

Solution code:
import sys
for s in sys.stdin:
  y,m,d=map(int,s[:-1].split())
  x=y*10000+m*100+d
  if x<18680908:print"pre-meiji"
  elif x<19120730:print"meiji",y-1867,m,d
  elif x<19261225:print"taisho",y-1911,m,d
  elif x<19890108:print"showa",y-1925,m,d
  else:print"heisei",y-1988,m,d

Submission status: Accepted

Solution code:
import sys
for s in sys.stdin:
  y,m,d=map(int,s[:-1].split())
  x=y*10000+m*100+d
  def f(i,w):
    print ["meiji","taisho","showa","heisei"][i],y-w,m,d
  if x<18680908:print"pre-meiji"
  elif x<19120730:f(0,1867)
  elif x<19261225:f(1,1911)
  elif x<19890108:f(2,1925)
  else:f(3,1988)

Submission status: Accepted

Solution code:
while True:
    try:
        lst = list(map(int, input().split()))

        num = lst[2] + 100*lst[1] + 10000*lst[0]

        if num >= 19890108:
            era = "heisei"
            lst[0] = lst[0] - 1988

        elif num >= 19261225:
            era = "showa"
            lst[0] = lst[0] - 1925

        elif num >= 19120730:
            era = "taisho"
            lst[0] = lst[0] - 1911

        elif num  >= 18680908:
            era = "meiji"
            lst[0] = lst[0] - 1867

        else:
            era = "pre-meiji"
            lst[0] = 0

        if lst[0] == 0:
            print(era)
        
        else:
            print(era + " " + str(lst[0]) + " " + str(lst[1]) + " " + str(lst[2]))
        
    except EOFError:
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write

def convert(y, m, d):
    if m <= 2:
        m += 12
        y -= 1
    mjd = int(365.25*y) + (y//400) - (y//100) + int(30.59*(m-2)) + d - 678912
    return mjd

def solve():
    A = convert(1868, 9, 8)
    B = convert(1912, 7, 30)
    C = convert(1926, 12, 25)
    D = convert(1989, 1, 8)
    for line in readlines():
        y, m, d = map(int, line.split())
        X = convert(y, m, d)
        if X < A:
            write("pre-meiji\n")
        elif X < B:
            write("meiji %d %d %d\n" % (y - 1867, m, d))
        elif X < C:
            write("taisho %d %d %d\n" % (y - 1911, m, d))
        elif X < D:
            write("showa %d %d %d\n" % (y - 1925, m, d))
        else:
            write("heisei %d %d %d\n" % (y - 1988, m, d))
solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from datetime import datetime

def gengo(y,m,d):
    date=datetime(y,m,d)
    if date<datetime(1868,9,8):
        return "pre-meiji"
    elif date<=datetime(1912,7,29):
        return "meiji {0} {1} {2}".format(y-1867,m,d)
    elif date<=datetime(1926,12,24):
        return "taisho {0} {1} {2}".format(y-1911,m,d)
    elif date<=datetime(1989,1,7):
        return "showa {0} {1} {2}".format(y-1925,m,d)
    else:
        return "heisei {0} {1} {2}".format(y-1988,m,d)

while True:
    try:
        y,m,d=[int(i) for i in input().split(" ")]
        print(gengo(y,m,d))
    except EOFError:
        break

Submission status: Accepted

Solution code:
while 1:
    try:
        a, b, c = map(int, input().split())
        x = a * 10000 + b * 100 + c

        if x <= 18680907:
            print('pre-meiji')
        elif 18680908 <= x and x <= 19120729:
            print('meiji', (a-67) % 100, b, c)
        elif 19120730 <= x and x <= 19261224:
            print('taisho', (a-11) % 100, b, c)
        elif 19261225 <= x and x <= 19890107:
            print('showa', (a-25) % 100, b, c)
        else:
            print('heisei', (a - 88) % 100, b, c)
    except:
        break

Submission status: Accepted

Solution code:
start_data = [18680908, 19120730, 19261225, 19890108, 99999999]
era = ["pre-meiji", "meiji", "taisho", "showa", "heisei"]

while 1:
    try:
        y, m, d = map(int, input().split(" "))
        data = y * 10000 + m * 100 + d
        for i in range(5):
            if data < start_data[i]:
                if i is 0:
                    print(era[0])
                    break
                else:
                    print(era[i], data // 10000 - start_data[i - 1] // 10000 + 1, m, d)
                    break
    except:
        break

Submission status: Accepted

Solution code:
while 1:
    try:
        year, month, day = map(int, input().split())
    except EOFError:
        break

    if year < 1868:
        gen = "pre-meiji"

    elif year == 1868:
        if month < 9:
            gen = "pre-meiji"
        elif month == 9:
            if day < 8:
                gen = "pre-meiji"
            else:
                gen = "meiji"
                y = 1
        else:
            gen = "meiji"
            y = 1

    elif 1868 < year < 1912:
        gen = "meiji"
        y = year - 1868 + 1

    elif year == 1912:
        if month < 7:
            gen = "meiji"
            y = 45
        elif month == 7:
            if day < 30:
                gen = "meiji"
                y = 45
            else:
                gen = "taisho"
                y = 1
        else:
            gen = "taisho"
            y = 1

    elif 1912 < year < 1926:
        gen = "taisho"
        y = year - 1912 + 1

    elif year == 1926:
        if month < 12:
            gen = "taisho"
            y = 15
        elif month == 12:
            if day < 25:
                gen = "taisho"
                y = 15
            else:
                gen = "showa"
                y = 1
        else:
            gen = "showa"
            y = 1

    elif 1926 < year < 1989:
        gen = "showa"
        y = year - 1926 + 1

    elif year == 1989:
        if month == 1:
            if day < 8:
                gen = "showa"
                y = 64
            else:
                gen = "heisei"
                y = 1
        else:
            gen = "heisei"
            y = 1

    elif 1989 < year:
        gen = "heisei"
        y = year - 1989 + 1

    if gen == "pre-meiji":
        print(gen)
    else:
        print(gen, str(y), str(month), str(day))

Submission status: Accepted

Solution code:
from bisect import bisect_left
import sys

name = ["pre-meiji", "meiji", "taisho", "showa", "heisei"]
period = [(1868,9,7), (1912,7,29), (1926,12,24), (1989,1,7)]

for t in (tuple(map(int, l.split())) for l in sys.stdin):
    index = bisect_left(period, t)
    if index:
        date = "{} {} {}".format(t[0]-period[index-1][0]+1, t[1], t[2])
        print(name[index], date)
    else:
        print(name[index])

Submission status: Accepted

Solution code:
while True:
	try:
		data = map(int, raw_input().split())
		if data[0] <= 1868 and data[1] <= 9 and data[2] < 8:
			gengo = 'pre-meiji'
		elif 1868 <= data[0] <= 1911:
			gengo = 'meiji' + ' ' + str(data[0]-1867)
		elif data[0] == 1912 and data[1] <= 7 and data[2] < 30:
			gengo = 'meiji 45'
		elif data[0] <= 1925:
			gengo = 'taisho' + ' ' + str(data[0]-1911)
		elif data[0] == 1926 and data[1] <= 12 and data[2] < 25:
			gengo = 'taisho 15'
		elif data[0] <= 1988:
			gengo = 'showa' + ' ' + str(data[0]-1925)
		elif data[0] == 1989 and data[1] == 1 and data[2] <8:
			gengo = 'showa 64'
		else:
			gengo = 'heisei' + ' ' + str(data[0]-1988)
			
		if gengo == 'pre-meiji':
			print gengo
		else:
			print gengo + ' ' +  str(data[1]) + ' ' + str(data[2])
	except EOFError:
		break

Submission status: Runtime Error

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:
    f = map(int, input().strip().split())
    print(era(f))

Submission status: Runtime Error

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

Submission status: WA: Presentation Error

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