Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

日本の暦 

「西暦」は西洋から輸入された概念ですが、日本には暦上の年を表す方法として「元号」に年を付けて識別する和暦という概念があります。例えば今年は西暦なら２０１６年ですが、和暦なら平成２８年です。どちらもよく使われる年の表現方法ですが、ある年の西暦がわかっていても和暦で何年かわからない、またはその逆の状況を経験したことはありませんか？

西暦で年が与えられたとき和暦の年を、和暦で年が与えられたとき西暦の年を出力するプログラムを作成せよ。ただし、西暦と和暦の対応は、簡単のため以下のようにする。

西暦
和暦

１８６８年から１９１１年
明治元年から明治４４年

１９１２年から１９２５年
大正元年から大正１４年

１９２６年から１９８８年
昭和元年から昭和６３年

１９８９年から２０１６年
平成元年から平成２８年

Input

入力は以下の形式で与えられる。 

E Y

入力は１行からなり、E (0 ≤ E ≤ 4) は与えられる暦の種類、Y はその暦での年であり、E が 0 のときは西暦 Y (1868 ≤ Y ≤ 2016)年、1 のときは和暦の明治 Y (1 ≤ Y ≤ 44)年、2 のときは和暦の大正 Y (1 ≤ Y ≤ 14)年、3 のときは和暦の昭和 Y (1 ≤ Y ≤ 63)年、4 のときは和暦の平成 Y (1 ≤ Y ≤ 28)年を表す。

Output

西暦ならば和暦に、和暦ならば西暦に変換した結果を、１行に出力する。ただし、西暦を和暦に変換した結果は、明治なら文字「M」、大正なら文字「T」、昭和なら文字「S」、平成なら文字「H」を先頭に付けて出力する。 

Sample Input 1

0 2015

Sample Output 1

H27

Sample Input 2

0 1912

Sample Output 2

T1

Sample Input 3

2 1

Sample Output 3

1912

Sample Input 4

4 28

Sample Output 4

2016



Sample input:
0 2015


Sample output:
H27

Submission status: Wrong Answer

Solution code:
E,Y = map(int,input().split())

if E ==0:
    if 1911>Y:
        print("M"+str(Y-1867))
    elif 1925>Y:
        print("T"+str(Y-1911))
    elif 1988>Y:
        print("S"+str(Y-1925))
    else:
        print("H"+str(Y-1988))
elif E==1:
    print(1868+Y)
elif E==2:
    print(1912+Y)
elif E==3:
    print(1926+Y)
else:
    print(1989+Y)

Submission status: Wrong Answer

Solution code:
E,Y = map(int,input().split())

if E ==0:
    if 1911>Y:
        print("M"+str(Y-1867))
    elif 1925>Y:
        print("T"+str(Y-1911))
    elif 1988>Y:
        print("S"+str(Y-1925))
    else:
        print("H"+str(Y-1988))
elif E==1:
    print(1867+Y)
elif E==2:
    print(1911+Y)
elif E==3:
    print(1925+Y)
else:
    print(1988+Y)

Submission status: Wrong Answer

Solution code:
def main():
    E,Y = map(int,input().split())
    if E == 0:
        if Y <= 1911:
            print("S"+str(Y-1867))
        elif Y <= 1925:
            print("T"+str(Y-1911))
        elif Y<= 1988:
            print("S"+str(Y-1925))
        else:
            print("H"+str(Y-1988))
    elif E == 1:
        print(str(1867+Y))
    elif E == 2:
        print(str(1911+Y))
    elif E == 3:
        print(str(1925+Y))
    else:
        print(str(1988+Y))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
c = [1868, 1912, 1926, 1989]

e, y = [int(num) for num in input().split()]
if e > 0:
    print(c[e - 1] + y - 1)
else:
    if y < c[1]:
        print('M{}'.format(y - c[0] + 1))
    elif y < c[2]:
        print('T{}'.format(y - c[1] + 1))
    elif y < c[3]:
        print('M{}'.format(y - c[2] + 1))
    else:
        print('H{}'.format(y - c[3] + 1))

Submission status: Accepted

Solution code:
E,Y = map(int,input().split())

if E ==0:
    if 1912>Y:
        print("M"+str(Y-1867))
    elif 1926>Y:
        print("T"+str(Y-1911))
    elif 1989>Y:
        print("S"+str(Y-1925))
    else:
        print("H"+str(Y-1988))
elif E==1:
    print(1867+Y)
elif E==2:
    print(1911+Y)
elif E==3:
    print(1925+Y)
else:
    print(1988+Y)

Submission status: Accepted

Solution code:
e, y = map(int, input().split())
if e == 0:
    if y >= 1989: print("H{}".format(y-1988))
    elif y >= 1926: print("S{}".format(y-1925))
    elif y >= 1912: print("T{}".format(y-1911))
    else: print("M{}".format(y-1867))
elif e == 1: # Meiji era
    print(1867+y)
elif e == 2: # Taisho era
    print(1911+y)
elif e == 3: # Showa era
    print(1925+y)
else: # Heisei era
    print(1988+y)

Submission status: Accepted

Solution code:
def main():
    E,Y = map(int,input().split())
    if E == 0:
        if Y <= 1911:
            print("M"+str(Y-1867))
        elif Y <= 1925:
            print("T"+str(Y-1911))
        elif Y<= 1988:
            print("S"+str(Y-1925))
        else:
            print("H"+str(Y-1988))
    elif E == 1:
        print(str(1867+Y))
    elif E == 2:
        print(str(1911+Y))
    elif E == 3:
        print(str(1925+Y))
    else:
        print(str(1988+Y))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
e, y = map(int, input().split())
W = "MTSH"
E = [1868, 1912, 1926, 1989, 2017]
if e == 0:
    for i in range(4):
        if E[i] <= y < E[i+1]:
            print("%s%d" % (W[i], y-E[i]+1))
            break
else:
    print(E[e-1]+y-1)

Submission status: Accepted

Solution code:
c = [1868, 1912, 1926, 1989]

e, y = [int(num) for num in input().split()]
if e > 0:
    print(c[e - 1] + y - 1)
else:
    if y < c[1]:
        print('M{}'.format(y - c[0] + 1))
    elif y < c[2]:
        print('T{}'.format(y - c[1] + 1))
    elif y < c[3]:
        print('S{}'.format(y - c[2] + 1))
    else:
        print('H{}'.format(y - c[3] + 1))

Submission status: Accepted

Solution code:
def solve(e,y):
    if e == 0:
        if y < 1912:
            r = 'M' + str(y-1868+1)
        elif y < 1926:
            r = 'T' + str(y-1912+1)
        elif y < 1989:
            r = 'S' + str(y-1926+1)
        else:
            r = 'H' + str(y-1989+1)
    else:
        yy = [0,1868,1912,1926,1989]
        r = yy[e] + y - 1

    return r

def main():
    E,Y = map(int,input().split())
    print(solve(E,Y))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
e, y = map(int, input().split())
if e == 0:
    if y < 1912:print("M" + str(y - 1867))
    elif y < 1926:print("T" + str(y - 1911))
    elif y < 1989:print("S" + str(y - 1925))
    else:print("H" + str(y - 1988))
else:print(y + (1867,1911,1925,1988)[e - 1])

Submission status: Accepted

Solution code:
def wa(y):
  if y <= 1911:
    return "M" + str(y - 1867)
  elif y  <= 1925:
    return "T" + str(y - 1911)
  elif y <= 1988:
    return "S" + str(y - 1925)
  else:
    return "H" + str(y - 1988)
def sei(e, y):
  if e == 1:
    return y + 1867
  elif e == 2:
    return y + 1911
  elif e == 3:
    return y + 1925
  else:
    return y + 1988 
e, y = map(int, input().split())
if e == 0:
  print(wa(y))
else:
  print(sei(e, y))

Submission status: Accepted

Solution code:
E, Y = map(int, input().split())
if E == 0 :
    if 1868 <= Y <= 1911 :
        print('M', Y-1867, sep='')
    elif 1912 <= Y <= 1925 :
        print('T', Y-1911, sep='')
    elif 1926 <= Y <= 1988 :
        print('S', Y-1925, sep='')
    else :
        print('H', Y-1988, sep='')

elif E == 1 :
    print(Y+1867)
elif E == 2 :
    print(Y+1911)
elif E == 3 :
    print(Y+1925)
else :
    print(Y+1988)

Submission status: Accepted

Solution code:
E, Y = map(int, input().split())
R = ''
if E==0:
	if 1868<=Y<=1911:
		R = 'M'+str(Y-1868+1)
	elif 1912<=Y<=1925:
		R = 'T'+str(Y-1912+1)
	elif 1926<=Y<=1988:
		R = 'S'+str(Y-1926+1)
	elif 1989<=Y<=2016:
		R = 'H'+str(Y-1989+1)
elif E==1:
	R = str(1868+Y-1)
elif E==2:
	R = str(1912+Y-1)
elif E==3:
	R = str(1926+Y-1)
elif E==4:
	R = str(1989+Y-1)
print(R)

Submission status: Accepted

Solution code:
e,y = map(int,input().split())

if e == 0:
    if 1868 <= y <= 1911:
        x = y - 1867
        print("M"+str(x))
    elif  1912 <= y <= 1925:
        x = y - 1911
        print("T"+str(x))
    elif  1926 <= y <= 1988:
        x = y - 1925
        print("S"+str(x))
    else:
        x = y-1988
        print("H"+str(x))

if e == 1:
    print(1867 + y)

if e == 2:
    print(1911 + y)

if e == 3:
    print(1925 + y)

if e == 4:
    print(1988 + y)

Submission status: Accepted

Solution code:
#標準入力
a,b = map(int,input().split())

#0なら西暦を和暦に変換する
if a == 0:
    if b > 1988:print("H" + str(b - 1988))
    elif b > 1925:print("S" + str(b - 1925))
    elif b > 1911:print("T" + str(b - 1911))
    else:print("M" + str(b - 1867))
    
#それ以外なら和暦を西暦にする
if a == 1:print(1867 + b)
if a == 2:print(1911 + b)
if a == 3:print(1925 + b)
if a == 4:print(1988 + b)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
if a == 0:
    if b > 1988:
        print("H{}".format(b-1988))
    elif b > 1925:
        print("S{}".format(b-1925))
    elif b > 1911:
        print("T{}".format(b-1911))
    else:
        print("M{}".format(b-1867))
elif a == 1:
    print(b+1867)
elif a == 2:
    print(b+1911)
elif a == 3:
    print(b+1925)
else:
    print(b+1988)

Submission status: Accepted

Solution code:
e,y=map(int, input().split())
if e == 0:
    if 1868 <= y <= 1911:
        print('M'+str(y-1867))
    elif 1912 <= y <= 1925:
        print('T'+str(y-1911))
    elif 1926 <= y <= 1988:
        print('S'+str(y-1925))
    elif 1989 <= y <= 2016:
        print('H'+str(y-1988))
elif e == 1:
    print(1867+y)
elif e == 2:
    print(1911+y)
elif e == 3:
    print(1925+y)
elif e == 4:
    print(1988+y)

Submission status: Accepted

Solution code:
L,R = input().split()
L = int(L)
R = int(R)

if L == 0:
    if R >= 1868 and R <= 1911:
        K = int(R) - 1867
        print("M" + str(K))
    elif R >= 1912 and R <= 1925:
        K = int(R) - 1911
        print("T" + str(K))
    elif R >= 1926 and R <= 1988:
        K = int(R) - 1925
        print("S" + str(K))
    elif R >= 1989 and R <= 2016:
        K = int(R) - 1988
        print("H" + str(K))
elif L == 1:
    K = int(R) + 1867
    print(K)
elif L == 2:
    K = int(R) + 1911
    print(K)
elif L == 3:
    K = int(R) + 1925
    print(K)
elif L == 4:
    K = int(R) + 1988
    print(K)

Submission status: Accepted

Solution code:
e,y=map(int,input().split())
if e==0:
    if 1868<=y<=1911:
        print ("M",y-1867 ,sep="")
    elif 1912<=y<=1925:
        print("T",y-1911,sep="")
    elif 1926<=y<=1988:
        print("S",y-1925,sep="")
    else :
        print("H",y-1988,sep="")
elif e==1:
    print(y+1867)
elif e==2:
    print(y+1911)
elif e==3:
    print(y+1925)
else:
    print (y+1988)

Submission status: Accepted

Solution code:
e,y = map(int,input().split(" "))

if e == 0:
  if y < 1912:
    print("M",y-1867,sep='')
  elif y < 1926:
    print("T",y-1911,sep='')
  elif y < 1989:
    print("S",y-1925,sep='')
  else:
    print("H",y-1988,sep='')
elif e == 1:
  print(y+1867)
elif e == 2:
  print(y+1911)
elif e == 3:
  print(y+1925)
elif e == 4:
  print(y+1988)

Submission status: Accepted

Solution code:
E, Y = map(int, input().split())
 
if E == 0:
    if 1868 <= Y <= 1911:
        ch = "M" + str(Y-1868+1)
    elif 1912 <= Y <= 1925:
        ch = "T" + str(Y-1912+1)
    elif 1926 <= Y <= 1988:
        ch = "S" + str(Y-1926+1)
    else:
        ch = "H" + str(Y-1989+1)
 
elif E == 1:
    ch = 1868 + Y - 1
elif E == 2:
    ch = 1912 + Y - 1
elif E == 3:
    ch = 1926 + Y - 1
else:
    ch = 1989 + Y - 1
 
print(ch)

Submission status: Accepted

Solution code:
e, y = map(int,input().split())

if e == 0:
    if y < 1912:
        a = y - 1867
        print("M", a, sep = '')
    elif y < 1926:
        a = y - 1911
        print("T", a, sep = '')
    elif y < 1989:
        a = y - 1925
        print("S", a, sep = '')
    elif y < 2017:
        a = y - 1988
        print("H", a, sep = '')
elif e == 1:
    a = 1867 + y
    print(a)
elif e == 2:
    a = 1911 + y
    print(a)
elif e == 3:
    a = 1925 + y
    print(a)
elif e == 4:
    a = 1988 + y
    print(a)

Submission status: Accepted

Solution code:
e,y=map(int,input().split())
ei=[0,1867,1911,1925,1988]
if e==0:
    if y>1988:
        print(f'H{y-1988}')
    elif y>1925:
        print(f'S{y-1925}')
    elif y>1911:
        print(f'T{y-1911}')
    else:
        print(f'M{y-1867}')
else:
    print(ei[e]+y)

Submission status: Accepted

Solution code:
e, y = map(int, input().split())

if e == 0:
    if 1868 <= y <= 1911:
        ans = "M" + str(y-1868+1)
    elif 1912 <= y <= 1925:
        ans = "T" + str(y-1912+1)
    elif 1926 <= y <= 1988:
        ans = "S" + str(y-1926+1)
    else:
        ans = "H" + str(y-1989+1)

elif e == 1:
    ans = 1868 + y - 1
elif e == 2:
    ans = 1912 + y - 1
elif e == 3:
    ans = 1926 + y - 1
else:
    ans = 1989 + y - 1

print(ans)

Submission status: Accepted

Solution code:
def jp(Y):
    if Y > 1988:
        return f"H{Y-1988}"
    elif Y > 1925:
        return f"S{Y-1925}"
    elif Y > 1911:
        return f"T{Y-1911}"
    elif Y > 1911:
        return f"T{Y-1911}"
    else:
        return f"M{Y-1867}"

def meiji(Y):
    return f"{1867+Y}"

def taisho(Y):
    return f"{1911+Y}"

def syowa(Y):
    return f"{1925+Y}"

def heisei(Y):
    return f"{1988+Y}"

E, Y = map(int, input().split())
print([jp(Y), meiji(Y), taisho(Y), syowa(Y), heisei(Y)][E])