結果

問題 No.2231 Surprising Flash!
ユーザー umncumnc
提出日時 2023-02-26 16:57:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,927 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 65,268 KB
実行使用メモリ 5,360 KB
最終ジャッジ日時 2023-10-12 07:58:13
合計ジャッジ時間 11,161 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 3 ms
4,352 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,352 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 17 ms
4,968 KB
testcase_12 AC 21 ms
5,200 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 16 ms
4,904 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,245 ms
5,024 KB
testcase_35 AC 1,240 ms
4,816 KB
testcase_36 AC 1,247 ms
5,112 KB
testcase_37 AC 1,245 ms
5,024 KB
testcase_38 AC 1,242 ms
4,832 KB
testcase_39 AC 9 ms
4,356 KB
testcase_40 AC 6 ms
4,348 KB
testcase_41 WA -
testcase_42 AC 2 ms
4,352 KB
testcase_43 AC 2 ms
4,356 KB
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

// 文字列S1の中に?があるかどうかを返す関数
bool has_question_mark(string S1) {
    for (char c : S1) {
        if (c == '?') return true;
    }
    return false;
}

// 文字列S1の中に?があればaに置き換える関数
void replace_question_mark(string& S1) {
    for (int i = 0; i < S1.size(); i++) {
        if (S1[i] == '?') S1[i] = 'a';
    }
}

// 文字列S2が文字列S1の連続する部分列として含まれるかどうかを返す関数
bool contains_substring(string S1, string S2) {
    // findメソッドやstrstr関数などを使って判定する
    // findメソッドは見つからない場合にstring::nposを返す
    // strstr関数は見つからない場合にNULLポインターを返す
    return (S1.find(S2) != string::npos);
}

int main() {
    int T; // テストケースの個数
    cin >> T;
    
    for (int t = 0; t < T; t++) {
        int N, M; // 文字列S1とS2の長さ
        string S1, S2; // 文字列S1とS2
        
        cin >> N >> M >> S1 >> S2;
        
        if (has_question_mark(S1)) { // ?がある場合
            replace_question_mark(S1); // ?をaに置き換える
            
            if (contains_substring(S1, S2)) { // 部分列として含まれる場合
                cout << S1 << endl; // 答えとして出力する
            } else { // 部分列として含まれない場合
                cout << -1 << endl; // -1 を出力する
            }
            
        } else { // ?がない場合
            
            if (contains_substring(S1, S2)) { // 部分列として含まれる場合
                cout << S1 << endl; // 答えとして出力する
            } else { // 部分列として含まれない場合
                cout << -1 << endl; // -1 を出力する 
            }
            
        }
        
    }
    
}
0