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の感想と自分が解いたところまでの解説を書いていきます
(今回はA~Bをpython、Aをjavaで書きます)
AtCoder Beginner Contest 427

1.感想

A問題:
少し悩んだ
B問題:
まあ簡単だった
一回CEしてしまった
C問題:
普通にわからん
難易度がおかしい気がした

2.結果

image.png
上がった、良かった

3.解説

A問題ABC -> AC

C++での解法

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

int main(){
    string S;
    cin >> S;
    
    for (size_t i = 0; i < S.size(); i++){
        if (i+i == S.size()-1) continue;
        cout << S[i];
    }
    
    cout << endl;
    return 0;
}

pythonでの解法

S = list(input())

for i in range(len(S)):
    if i+i == len(S)-1:
        continue
    print(S[i], end='')
print()

javaでの解法

import java.util.*;

public class Main{
    static Scanner javain = new Scanner(System.in);
    
    public static void main(String[] rgs){
        String S = javain.next();
        for (int i = 0; i < S.length(); i++){
            if (i+i == S.length()-1) continue;
            System.out.print(S.charAt(i));
        }
        System.out.println();
    }
}

B問題Sum of Digits Sequence

C++での解法

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

ll F(ll N){
    ll res = 0;
    while (N > 0){
        res += N%10;
        N /= 10;
    }
    return res;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> A;
    
    for (int i = 0; i <= N; i++){
        if (i == 0){
            A.push_back(1);
            continue;
        }
        int res = 0;
        for (int j : A) res += F(j);
        A.push_back(res);
    }
    
    cout << A.back() << endl;
    return 0;
}

pythonでの解法

def F(N):
    res = 0
    while N > 0:
        res += N%10
        N //= 10
    return res;

N = int(input())
A = []

for i in range(N+1):
    if i == 0:
        A.append(1)
        continue
    res = 0
    for j in A:
        res += F(j)
    A.append(res)

print(A[N])
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?