QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#678829 | #7262. String Modification | Imran_86 | WA | 0ms | 3516kb | C++20 | 1.4kb | 2024-10-26 16:14:48 | 2024-10-26 16:14:48 |
Judging History
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