UVA10340子序列
题意:
给你两个串,问你第二个第一个串是否是第一个串删除0个或多个字母得到的?
思路:
直接模拟就行了,在第二个串中去按顺序更新第一个串的下标,好像没说明白啊,不管了,水题,不理解直接看下代码就懂了。
#include<stdio.h>
#include<string.h>
char str1[1100000] ,str2[1100000];
int main ()
{
while(~scanf("%s %s" ,str1 ,str2))
{
int l1 = strlen(str1);
int l2 = strlen(str2);
if(l1 > l2)
{
puts("No");
continue;
}
int nowid = 0;
for(int i = 0 ;i < l2 ;i ++)
{
if(str2[i] == str1[nowid])
nowid ++;
if(nowid == l1) break;
}
nowid == l1 ? puts("Yes") : puts("No");
}
return 0;
}
UVA10340子序列的更多相关文章
- 子序列 (All in All,UVa10340)
题目描述:算法竞赛入门经典习题3-9 题目思路:循环匹配 //没有按照原题的输入输出 #include <stdio.h> #include <string.h> #defin ...
- 用python实现最长公共子序列算法(找到所有最长公共子串)
软件安全的一个小实验,正好复习一下LCS的写法. 实现LCS的算法和算法导论上的方式基本一致,都是先建好两个表,一个存储在(i,j)处当前最长公共子序列长度,另一个存储在(i,j)处的回溯方向. 相对 ...
- codevs 1576 最长上升子序列的线段树优化
题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...
- [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- [LeetCode] Is Subsequence 是子序列
Given a string s and a string t, check if s is subsequence of t. You may assume that there is only l ...
- [LeetCode] Wiggle Subsequence 摆动子序列
A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...
- [LeetCode] Increasing Triplet Subsequence 递增的三元子序列
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- [LeetCode] Distinct Subsequences 不同的子序列
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- 动态规划之最长公共子序列(LCS)
转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...
随机推荐
- HDOJ-4027(线段树+区间更新(每个节点更新的值不同))
Can You answer these queries? HDOJ-4027 这道题目和前面做的题目略有不同.以前的题目区间更新的时候都是统一更新的,也就是更新相同的值.但是这里不一样,这里更新的每 ...
- Codeforces 1167c(ccpc wannafly camp day1) News Distribution 并查集模板
题目: In some social network, there are nn users communicating with each other in mm groups of friends ...
- Java 面向对象 01
面向对象·一级 面向对象思想概述 * A:面向过程思想概述 * 第一步 * 第二步 * B:面向对象思想概述 * 找对象(第一步,第二步) * C:举例 * 买煎饼果子 ...
- VUE中的子父组件、兄弟组件之间相互传值,相互调用彼此的方法
vue--组件传值 父组件传值给子组件--"props" 一.父组件--示例 <template> <child :choose-data="choos ...
- Java基础:特性write once;run anywhere!
三高:高可用 高性能 高并发 特性: 简单性 面向对象:万物皆为对象 可移植性 高性能 分布式 动态性 多线程 安全性 健壮性 Java三大版本 javaSE:标准版(桌面程序,控制台) javaME ...
- nginx安装&负载均衡配置&nginx反爬虫&nginx命令
Nginx安装 wget https://nginx.org/download/nginx-1.14.0.tar.gz tar -zxvf nginx-1.14.0.tar.gz cd nginx-1 ...
- 浅析MyBatis(二):手写一个自己的MyBatis简单框架
在上一篇文章中,我们由一个快速案例剖析了 MyBatis 的整体架构与整体运行流程,在本篇文章中笔者会根据 MyBatis 的运行流程手写一个自定义 MyBatis 简单框架,在实践中加深对 MyBa ...
- python 查看模块中的方法
way 1.help() way 2.dir() # dir() 函数不带参数时,返回当前范围内的变量.方法和定义的类型列表: way 3. 使用inspect模块, inspect.getmembe ...
- 国产mcu理论数据评估工作记录
目录 前言 简要工作记录 前言 时间:20210315 主要记录这两天对国内各IC厂商的 MCU 了解记录. 大环境,ST 厂商 MCU 疯狂涨价,国内 MCU 也越来越完善,还便宜.同时,全球缺晶圆 ...
- Java代码实现热部署
一.思路 0. 监听java文件最后修改时间,如果发生变化,则表示文件已经修改,进行重新编译 1. 编译java文件为 class文件 2. 通过手写类加载器,加载 class文件 ,创建对象 3. ...