UVa 10340 – All in All
You've devised a new encryption technique that encodes messages by inserting randomly generated strings between the characters of the message. Due to unresolved patent issues, we won't delve into how to generate these strings. However, to validate your method, it's necessary to write a program to check if a message is truly encoded in the final string. Given two strings, S and T, you must determine whether S is the original message string of T, meaning it can be obtained by deleting characters from T to concatenate the remaining characters into S.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
EOF inputs: each line contains two strings, S and T, consisting only of English letters. | For each line of input: If S is the original message string of T, output "Yes". Otherwise, output "No". |
sequence subsequence person compression VERDI vivaVittorioEmanueleReDiItalia caseDoesMatter CaseDoesMatter | Yes No Yes No |
Thought Process
Run a for loop over the second string and set a variable called Count (initialized to 0). When the i-th character of the second string equals the Count-th character of the first string, increment Count. Finally, check if Count equals the length of the first string.
Sample Code-ZeroJudge E624: All in All
#include <iostream>
using namespace std;
int main() {
string a, b;
while (cin >> a >> b)
{
int count = 0;
for (int i = 0; i<b.length(); i++)
{
if (b[i] == a[count]) count++;
if (count == a.length()) break;
}
if (count == a.length()) cout << "Yes\n";
else cout << "No\n";
}
}
//ZeroJudge E624
//Dr. SeanXD