寝癖頭の解法

学習中の覚え書きを投稿、更新していきます。

AtCoder Problems in C++ #C - Dubious Document 2

AtCoder Beginner Contestの過去問から、その提出コードの解答例です。
AtCoderとは、コンテストを通じて、プログラミングやアルゴリズムを学習するサービスです。
atcoder.jp
プログラミングコンテストとは、「与えられた問題をいかに素早く、正確に」解くことができるかを競うものです。
競技プログラミング」を略して、「競プロ」などと呼ばれています。

#C - Dubious Document 2
atcoder.jp

僕が作成、提出したコードは、以下のとおりです。

/*
AtCoder Problems in C++
#C - Dubious Document 2
https://atcoder.jp/contests/abc076/tasks/abc076_c
提出コードの解答例
https://neguse-atama.hatenablog.com
*/
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s,t;
  cin>>s>>t;
  for(int i=s.size()-1; i>=0; i--){
    bool tf=true;
    for(int j=t.size()-1; j>=0;j--){
      if(t[j]==s[i-t.size()+1+j] || s[i-t.size()+1+j]=='?'){
        
      }else{
        tf=false;
        break;
      }
    }
    if(tf){
      for(int j=0;j+t.size()<i+1;j++){
        cout<<(s[j]=='?' ? 'a' : s[j]);
      }
      cout<<t;
      for(int j=i+1;j<s.size();j++){
        cout<<(s[j]=='?' ? 'a' : s[j]);
      }
      cout<<endl;
      return 0;
    }
  }
  cout<<"UNRESTORABLE"<<endl;
  return 0;
}

AtCoder Beginner Contestは、オンラインジャッジによるプログラミングコンテストです。
日本語と英語に対応していて、週末ごとに実施されているみたいです。
https://practice.contest.atcoder.jp/tutorial
アカウントを登録すれば、誰でも参加できます。