0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AtCoder426の感想と自分が解いたところまでの解説を書いていきます
Rubyをある程度習得したので次からはRubyでも書いていこうと思います。)
(今回はA~Bをpython、AをRubyで書きます)
AtCoder Beginner Contest 426

1.感想

A問題:
コードの量は長めだった
一回WAしてしまった
B問題:
とても簡単だった
C問題:
わからんなんか6回ぐらい出して全部TLEした
何故か1個だけE問題のところに出してしまった
難易度がおかしい気がした

2.結果

image.png

3.解説

A問題OS Versions

C++での解法

#include <bits/stdc++.h>
using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    
    if (T == "Ocelot" && S == "Serval") puts("Yes");
    else if (T == "Ocelot" && S == "Lynx") puts("Yes");
    else if (T == "Serval" && S == "Lynx") puts("Yes");
    else if (S == T) puts("Yes");
    else puts("No");
    
    return 0;
}

pythonでの解法

S, T = input().split()

if S == "Serval" and T == "Ocelot":
    print("Yes")
elif S == "Lynx" and T == "Ocelot":
    print("Yes")
elif S == "Lynx" and T == "Serval":
    print("Yes")
elif S == T:
    print("Yes")
else:
    print("No")

Rubyでの解法

s, t = gets.chomp.split

if s == t
    puts "Yes"
elsif s == "Serval" and t == "Ocelot"
    puts "Yes"
elsif s == "Serval" and t == "Ocelot"
    puts "Yes"
elsif s == "Lynx"
    puts "Yes"
else
    puts "No"
end

B問題The Odd One Out

C++での解法

#include <bits/stdc++.h>
using namespace std;

int main(){
    string S;
    pair<char, int> A = {'-', 0}, B = {'-', 0};
    cin >> S;
    
    for (char i : S){
        if (A.first == '-') A.first = i, A.second++;
        else if (A.first == i) A.second++;
        else if (A.first != i && B.first == '-') B.first = i, B.second++;
        else B.second++;
    }
    
    if (A.second == 1) cout << A.first << endl;
    else cout << B.first << endl;
    return 0;
}

pythonでの解法

S = list(input())
char1, char2 = '-', '-'
count1, count2 = 0, 0

for i in S:
    if char1 == '-':
        count1 += 1
        char1 = i
    elif char1 != i:
        char2 = i
        count2 += 1
    else:
        count1 += 1

print(char1 if count1 == 1 else char2)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?