UVA10340 POJ1936 ZOJ1970 All in All

问题链接:UVA10340 POJ1936 ZOJ1970 All in All。入门练习题,用C语言编写程序。

题意简述:输入两个字符串s和t,看s是否是t的子串。t中的字符可以任意删除,只要顺序匹配字符串就可以。

AC的C语言程序如下:

/* UVA10340 POJ1936 ZOJ1970 All in All */

#include <stdio.h>
#include <string.h>

#define MAXN 110000

char s[MAXN], t[MAXN];

int delstrcmp(char *s, char *t)
{
    int i, j, slen, tlen;

    slen = strlen(s);
    tlen = strlen(t);

    for(i=0, j=0; i<slen && j<tlen;) {
        if(s[i] == t[j]) {
            i++;
            j++;
        } else
            j++;
    }

    return i == slen;
}

int main(void)
{
    while(scanf("%s%s", s, t) != EOF)
        printf("%s\n", delstrcmp(s, t) ? "Yes" : "No");

    return 0;
}
时间: 2024-08-08 13:47:51

UVA10340 POJ1936 ZOJ1970 All in All的相关文章

UVa10340

All in All 题意:字符串匹配 #include <stdio.h> #include <string.h> char S[200000]; char P[200000]; int next[200000]; int KMP(int pos, int len1, int len2) { int i = pos, j = 1, k = 0; next[1] = 0; while (j < len1) if (k == 0 || P[k - 1] == P[j - 1])

UVa10340.All in All

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1281 13845990 10340 All in All Accepted C++ 0.026 2014-07-07 15:05:55 All in All Input: standard input Output: standard output Time Limit: 2 se

poj1936(All in All)

题目地址:All in All 题目大意: 判断后一个字符串是否包含前一个字符串,顺序不能改变. 解题思路: 以后一个字符串为循环,与要判断的字符串中的字符相等就cnt++.最后cnt==len(需要判断的字符串)是输出YES否则NO. 代码: 1 #include <algorithm> 2 #include <iostream> 3 #include <sstream> 4 #include <cstdlib> 5 #include <cstrin

poj1936

非连续子串匹配题,直接模拟 /** \brief poj 1936 * * \param date 2014/8/5 * \param state AC * \return memory 804k time 0ms * */ #include <iostream> #include <fstream> #include <cstring> using namespace std; const int MAXN=100000; char s[MAXN]; char t[M

UVA10340 All in All子序列

Problem E All in All Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a cleve

UVA10763:Foreign Exchange&amp;&amp;UVA10340: All in All(水题)

10763:水题不解释直接贴代码. #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <math.h> #include <queue> #define eps 1e-9 typedef long long ll; using namespace std; int n; int d[500100]; int

[POJ1936]All in All

题目大意:读入两个字符串$s1$和$s2$,要你判断$s1$是不是$s2$的子串. 思路:模拟,用$a1$,$a2$两个指针表示当前判断到的位置.如果$s1[a1]$等于$s2[a2]$,则$s1$+1,$s2$+1,否则$s2$+1.最后如果所有字符全都判断成功,则输出“Yes”,否则“No”.(看似很长,实际上很简单) C/C++ Code: 1 #include<stdio.h> 2 #include<string.h> 3 char s1[100005],s2[100005

zoj1970||poj 1936 All in All

注意细节,一直把Yes,写成YES,找错误找了老半天都找不出来.... 代码如下: #include<stdio.h> #include<string.h> int main() { char s[100005],t[100005]; int m,i,j,n; while(scanf("%s%s",s,t)!=EOF) { m=strlen(t); n=strlen(s); i=0; for(j=0;j<m;j++)//关键步骤,只判定b数组是否到头,复杂

POJ1035&amp;&amp;POJ3080&amp;&amp;POJ1936

字符串处理专题,很早就写好了然而忘记写blog了 1035 题意:给你一些单词作为字典.然后让你查找一些单词.对于每个单词,如果在字典中就输出它.否则输出所有它通过删除||增加||替换一个字符能得到的单词 由于数据范围很小,所以我们直接暴力跑一下即可 CODE #include<string> #include<iostream> #include<map> using namespace std; const int N=10005; map <string,b