UVA-10340 All in All

UVA-10340 All in All

题目大意:两个字符串 s 和 t,判断 s 是否可以从 t 中删除字符得到。

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

解题思路:对字符串 s1 和 s2,如果相等,则对 s1,s2 后一位进行判断;如果不相等,则仅对 s2 右移一位。

#include   
#include 
using namespace std;
const int MAXN = 101000;
char s1[MAXN], s2[MAXN];
int main()
{
    while (cin >> s1 >> s2) {
        int i, j;
        int len1 = strlen(s1), len2 = strlen(s2);
        for (i = j = 0; i < len1 && j < len2;) {
            if (s1[i] == s2[j])
                i++, j++;
            else
                j++;
        }
        if (i == len1)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

你可能感兴趣的:(acm)