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?

AtCoder 勉強記録[C++] その52

Posted at

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

本日解いた問題

B - Longest Uncommon Prefix

B - Longest Uncommon Prefix
解答

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

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  for(int i = 1; i < n; i++){
    ll res = 0;
    for(int j = 0; j < n-i; j++){
      if(s[j]!=s[j+i]) res = j+1;
      else break;
    }
    cout << res << endl;
  }
}

解法

0からN-1までのjの間で、0からNまでのiにおいてS[j] = S[j+i]である場合のjの最大値を求める。

B - Cat

B - Cat
解答

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

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  while(1){
    bool jud = true;
    for(int i = 0; i < s.size(); i++){
      string na = s.substr(i, 2);
      if(na == "na") {
        s.insert(i+1, "y");
        jud = false;
        break;
      }
    }
    if(jud) break;
  }
  cout << s << endl;
}

解法

文字列Sにおいてある2文字がnaであった場合、間にyを挿入することで結果が求まる。

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?