uva 10340 All in All(字符串处理)

uva 10340 All in All

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings
are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string.

Given two strings s and t, you have to decide whether
s is a subsequence of t, i.e. if you can remove characters from
t such that the concatenation of the remaining characters is s.

Input Specification

The input contains several testcases. Each is specified by two strings
s, t of alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF.

Output Specification

For each test case output, if s is a subsequence of
t.

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

题目大意:给出两个字符串,判断串1是否为串2的子串,这里的子串不要求在串2中连续,但是要保证顺序一致。

解题思路:一个一个比。

#include<stdio.h>
#include<string.h>
char A[100000], B[100000];
int main() {
	while (scanf("%s %s\n", A, B) == 2) {
		int lenA = strlen(A);
		int lenB = strlen(B);
		int j = 0, i;
		for (i = 0; i < lenA, j < lenB;) {
				if (A[i] == B[j]) {
					j++;
					i++;
				}
				else {
					j++;
				}
		}
		if (i == lenA) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}
时间: 2024-10-30 19:24:13

uva 10340 All in All(字符串处理)的相关文章

uva 10391 Compound Words (字符串-hash)

Problem E: Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that is theconcatenation of exactly two other words in the dictionary. Input Standard input consists of a

UVA 261 - The Window Property(字符串Hash)

UVA 261 - The Window Property 题目链接 题意:这题题意挺绕的..就是给定一个字符串长度n,扫描长度为k = [1,n],然后每次只能扫描连续k个字符的子串,要求所有扫描中,每次扫描中出现的不同字符串个数都不超过k + 1,那么这个字符串就是window property,如果不是的话,就还要找出下标最小的不符合的位置(就是n次扫描中找最小的) 思路:Hash大法好,长度才100,直接处理出hash,O(n^2)随便搞掉 代码: #include <cstdio>

UVa 10340 字符串基础

背景:小紫书习题,开始数组开小了runtime error了一次,显然数组越界.复杂度:O(max(A的长度,B的长度)). 题意:看字符串A是不是字符串B的子串.直接顺序扫描即可. #include<stdio.h> #include<string.h> char str[1000000],ttr[1000000]; int main(void){ while(scanf("%s %s",str,ttr)!=EOF){ int j=0,sj=strlen(st

UVA - 10340 - All in All (字符串处理!)

题目链接: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 st

UVA 10941 - Words adjustment(BFS+字符串处理)

UVA 10941 - Words adjustment 题目链接 题意:给定两个字符串,在给定一些单词集合,问能否两个单词后面各添加一些单词,使得两个单词变成相同,问添加单词最少几次,单词要来自单词集合 思路:广搜,记录状态为两个字符串之间差的字符,利用set和string去乱搞..即可 代码: #include <cstdio> #include <cstring> #include <string> #include <iostream> #inclu

UVA 706 LCD Display 液晶显示屏 (字符串模拟)

[题目链接]click here~~ [题目大意] 给定的数字序列,按照要求输出对应液晶显示屏上的数字 输入: 2 12345 3 67890 0 0 输出: -- -- -- | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | -- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- | | | | | | | |

uva 1339 Ancient Cipher(字符串处理)

uva 1339 Ancient Cipher Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. T

UVa 401 Palindromes(简单字符串)

简单的判断是否是回文串.镜像串,然后自己写的真费劲,没逃掉刘汝佳的书,这里的代码很有技巧性,特别值得学习,额,其实他书上的代码都很精简 Character Reverse Character Reverse Character Reverse A A M M Y Y B   N   Z 5 C   O O 1 1 D   P   2 S E 3 Q   3 E F   R   4   G   S 2 5 Z H H T T 6   I I U U 7   J L V V 8 8 K   W W

UVa 10340 All in All

判断两字符串是否匹配 暴力出,注意数组要开大一点. 附AC代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 6 char s[100010],t[100010]; 7 8 int main(){ 9 while(cin>>s>>t){ 10 if(strstr(t,s)){//直接判断是否为字母串 11 cout<