QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678829#7262. String ModificationImran_86WA 0ms3516kbC++201.4kb2024-10-26 16:14:482024-10-26 16:14:48

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 16:14:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3516kb
  • [2024-10-26 16:14:48]
  • 提交

answer

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

void solve() {
    string s, t;
    cin >> s >> t;

    if (s[0] != t[0]) {
        // If the first characters don't match, return "No"
        cout << "No" << endl;
        return;
    }

    int j = 0;  // Pointer for string t
    int n = s.size();
    int m = t.size();

    for (int i = 0; i < n; ++i) {
        if (s[i] == t[j]) {
            // Characters match, move both pointers forward
            j++;
        } else {
            // If characters don't match, check if t[j] matches the previous character in s
            if (j > 0 && t[j] == t[j - 1]) {
                // t[j] matches the previous character in t, so we move forward in t
                j++;
                i--;  // Stay on the same character of s
            } else {
                // If we can't perform a valid insertion, output "No"
                cout << "No" << endl;
                return;
            }
        }

        // If we match all characters in t, we can stop early
        if (j == m) {
            cout << "Yes" << endl;
            return;
        }
    }

    // If we finish processing s but haven't matched all of t, output "No"
    cout << "No" << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();  // Process one test case

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3516kb

input:

snuke
snukent

output:

No

result:

wrong answer expected YES, found NO