初心者のプログラミング日記

プログラミング初心者の日記

プログラミングに関することを書いていきます。

ABC149(A~D)

A - Strings

https://atcoder.jp/contests/abc149/tasks/abc149_a

S,T=map(str,input().split())

print(T+S)

B - Greedy Takahashi

https://atcoder.jp/contests/abc149/tasks/abc149_b

A,B,K=map(int,input().split())

A,B,K=map(int,input().split())

if A-K<=0:
    num=abs(A-K)
    if B-num<=0:
        print(0,0)
    else:
        print(0,abs(B-num))
else:
    print(A-K,B)

C - Next Prime

https://atcoder.jp/contests/abc149/tasks/abc149_c

X=int(input())

def main(X):
    for i in range(2,X):
        if X%i==0:
            return False
    return True

if __name__ == "__main__":
    while True:
        if main(X):
            print(X)
            exit()
            
        X+=1

D - Prediction and Restriction

https://atcoder.jp/contests/abc149/tasks/abc149_d

N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(map(str,input()))
ta=[]

#出す手のリストを作る
for i,j in enumerate(T):
    if i>=K:
        if j=="r":
            if ta[i-K]=="パー":
                ta.append("グー")
            else:
                ta.append("パー")
        elif j=="s":
            if ta[i-K]=="グー":
                ta.append("チョキ")
            else:
                ta.append("グー")
        else:
            if ta[i-K]=="チョキ":
               ta.append("パー")
            else:
               ta.append("チョキ")
    else:
        if j=="r":
            ta.append("パー")
        elif j=="s":
            ta.append("グー")
        else:
           ta.append("チョキ")
ans=0  
#勝利判定
for i in range(len(T)):
    if T[i]=="r" and ta[i]=="パー":
        ans+=P
    elif T[i]=="s" and ta[i]=="グー":
        ans+=R
    elif T[i]=="p" and ta[i]=="チョキ":
        ans+=S
    
print(ans)

スマートな解き方がわからなかったので愚直に書きました