The second past question that I have already solved
Just output the closer one
answerA.py
x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
    print("A")
else:
    print("B")
I feel like I want to use the ternary operator as well ↓
answerA_better.py
x,a,b=map(int,input().split())
print("A" if abs(x-a)<abs(x-b) else "B")
//qiita.com/okkn/items/3aef4458ed2269a59d63)I referred to).. Once you have created the list, you can check if each alphabet appears.
#### **`answerB.py`**
```python
x=[chr(i) for i in range(97, 97+26)]
y=[0]*26
s=input()
for i in s:
    y[x.index(i)]=1
for i in range(26):
    if y[i]==0:
        print(chr(97+i))
        break
else:
    print("None")
Arrange them in order from the largest, and use the groupby function to arrange the length of each bar and its number as a set in order from the front. At that time, it may be considered separately depending on whether there are four or more cases or two or more cases.
answerC.py
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
x,y=0,0
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
b=groupby(a)
l=len(b)
for i in range(l):
    if x==0:
        if b[i][1]>=4:
            x,y=b[i][0],b[i][0]
        elif b[i][1]>=2:
            x=b[i][0]
    elif y==0:
        if b[i][1]>=2:
            y=b[i][0]
    else:
        break
print(x*y)
There are two ways to arrange them vertically or two horizontally, and consider each as one unit. (The former is 1 and the latter is 0.) Also, you can see how many ways to paint each of these units depending on the color of the adjacent unit (3 ways when 0 → 0, 0 → 1). 1 way when 1 → 0, 2 ways when 1 → 1). After that, you can easily find it by noting that you want more than 1000000007. (** It is important to experiment, grasp the characteristics, and reduce it to a simple problem **)
answerD.py
n=int(input())
d=[]
s1=input()
s2=input()
i=0
while i<n:
    if s1[i]==s2[i]:
        i+=1
        d.append(1)
    else:
        i+=2
        d.append(0)
l=len(d)
if d[0]==0:
    ans=6
else:
    ans=3
for i in range(1,l):
    if d[i-1]==1:
        ans*=2
        ans=ans%1000000007
    elif d[i]==0:
        ans*=3
        ans=ans%1000000007
print(ans)
        Recommended Posts