0
0

AtCoderで入茶を目指して勉強しています。
勉強を継続するために投稿を始めました。
もともとアカウントを作成していましたが、今年の4月から本格的に勉強を始めました。
一応自分用に解法を書いていますが雑です、自分で読み返して困ったら修正します。
私のアカウント
解いた問題

本日解いた問題

B - 81

B - 81
解答

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >> n;
  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      if(i*j == n){
        cout << "Yes" << endl;
        exit(0);
      }
    }
  }
  cout << "No" << endl;
}

解法

1から9までの掛け算のループを行いNと一致したらYes、一致しなかったらNoを出力する。

B - Count ABC

B - Count ABC
解答

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll res = 0;
  for(int i = 0; i < n - 2; i++){
    if(s[i] == 'A'&&s[i+1] == 'B'&&s[i+2] == 'C') res++;
  }
  cout << res << endl;
}

解法

文字列の最初の要素からABCになっているか判定する。

B - ATCoder

B - ATCoder
解答

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  ll i = 0, res = 0, tmp = 0;
  for(int i = 0; i < n; i++){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') {
      tmp++;
      res = max(tmp, res);
    }
    else{
      tmp = 0;
    }
  }
  cout << res << endl;
}

解法

文字列の最初からACGTのどれかであればカウントして、違う場合はリセットして続ける。カウントしたものの最大値を出力する。

C - Digits in Multiplication

C - Digits in Multiplication
解答

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >> n;
  ll a = sqrt(n);
  ll tmp = 0, res = INT_MAX;
  for(int i = 1; i <= a; i++){
    if(n%i!=0) continue; 
    ll b = n / i;
    string sta = to_string(i);
    string stb = to_string(b);
    ll diga = sta.size(), digb = stb.size();
    tmp = max(diga, digb);
    res = min(res, tmp);
  }
  cout << res << endl;
}

Aが1からNの平方数までの値でA×Bとなる要素を全探索する。桁数は文字列に変換して文字数にして求める。

C - Half and Half

C - Half and Half
解答

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int res = INT_MAX;
  int n = max(x,y);
  for(int i = 0; i <= n; i++){
    int dx = max(0, x-i);
    int dy = max(0, y-i);
    int tmp = c*2*i + a*dx + b*dy;
    res = min(tmp, res);
  }
  cout << res << endl;
}

解法

ABピザの枚数を0からXYのうち大きいほうの値まで全探索する。そのうちの最小値を出力する。

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