每个输入包含一个测试用例。每个测试用例包含两行长度不超过 10 的不包含空格的可见 ASCII 字符串。
输出一行 “Yes” 或者 “No” 表示结果。
nowcodecom ooo
Yes
#include<iostream> #include<string> using namespace std; int main(){ string str; while (cin >> str){ string str1; cin >> str1; int a=0, b = 0; while (a < str.length()){ if (str[a++] == str1[b]) b++; } if (b == str1.length()) cout << "Yes" << endl; else cout << "No" << endl; } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()){ char[] arr1 = sc.next().toCharArray(); char[] arr2 = sc.next().toCharArray(); int i=0,j=0; while (j<arr2.length && i<arr1.length){ if(arr1[i] == arr2[j]){ i++; j++; }//if else{ i++; }//else } if(j==arr2.length) System.out.println("Yes"); else System.out.println("No"); }//while sc.close(); } }
import re
str1 = input()
str2 = input()
item = ""
for i in str2:item +=".*"+i
item += ".*"
if re.search(item, str1):print("Yes")
else:print("No")
import java.util.*; public class Main { public static final void main(String[] args){ Scanner scan=new Scanner(System.in); while(scan.hasNext()){ String str1=scan.nextLine(); String str2=scan.nextLine(); boolean result=isContain(str1,str2); if(result){ System.out.println("Yes"); }else{ System.out.println("No"); } } scan.close(); } public static boolean isContain(String str1,String str2){ for(int i=0,index=0;i<str1.length();i++){ if(str1.charAt(i)==str2.charAt(index)){ index++; if(index==str2.length()){ return true; } } } return false; } }
#include <bits/stdc++.h>
using namespace std;
int main() {
char s1[10000],s2[10000];
scanf("%s %s",s1,s2);
int len1=strlen(s1),len2=strlen(s2),t=0,cnt=0;
for(int i=0; i<len2; i++) {
for(int j=t; j<len1; j++) {
if(s1[j]==s2[i]) {
t=j+1,cnt++;
break;
}
}
if(cnt==len2) {
cout<<"Yes"<<endl;
break;
}
}
if(cnt!=len2)
cout<<"No"<<endl;
return 0;
}
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String str=sc.nextLine(); String aim=sc.nextLine(); System.out.print(flag(str,aim,0,"")?"Yes":"No"); } public static boolean flag(String str,String aim,int i,String sum){ if(i==str.length()){ return sum.equals(aim); } return flag(str,aim,i+1,sum)||flag(str,aim,i+1,sum+str.charAt(i)); } }
import java.util.Scanner; public class Main{ public static void main(String []args) { Scanner sc = new Scanner(System.in); String s=sc.nextLine(); String t=sc.nextLine(); if(check(s,t)){ System.out.println("Yes"); } else{ System.out.println("No"); } } public static boolean check(String s,String t){ char []arr=t.toCharArray(); for(int i=0;i<arr.length;i++){ if(s.indexOf(arr[i])==-1) return false; if(s.indexOf(arr[i])!=-1) { s = s.substring(s.indexOf(arr[i]) + 1); } } return true; } }
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int main()
{
char a[12],b[12],t=0;
int p=0;
cin>>a>>b;
for(int i=0;i<strlen(b);i++)
{
for(int j=t;j<strlen(a);j++)
{
if(a[j] == b[i])
{
p++;//匹配成功则p加1
t = j+1;//下次接着这次检查到的a的位置继续检查下去
break;//跳出循环,检查b的下一个字符
}
}
}
if(p == strlen(b))//只要b全部字符都能匹配到,则证明b是a的子集
cout<<"Yes";
else
cout<<"No";
}
string.find(str, beg=0, end=len(string))
s='absdefgh' sub='asdf'
s=input() sub=input() index=0 flag='Yes' for i in sub: #利用 find函数 寻找子字符串中 每个字符的位置,其中index为初始位置,如果当前的字符存在, #则下一次寻找范围应该再当前字符位置后,故index=index+1 index1=s.find(i,index,len(s)) if index1!=-1: index=index1+1 else: flag='No' print(flag)
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String origin = scan.nextLine(); String target = scan.nextLine(); System.out.println(get_treasure(origin, target)); scan.close(); } private static String get_treasure(String origin, String target) { int[][] dp = new int[origin.length() + 1][target.length() + 1]; for(int i = 1; i <= origin.length(); i++){ for(int j = 1; j <= target.length(); j++){ if(origin.charAt(i - 1) == target.charAt(j - 1)){ dp[i][j] = dp[i - 1][j - 1] + 1; } else{//如果不等,则取前三种公共子串长度中的最大长度作为当前子串的最大长度 dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1][ j - 1]); } } } return dp[origin.length()][target.length()] == target.length() ? "Yes" : "No"; } private static int max(int i, int j, int k) { return (i > j) ? ( i > k ? i : k) : (j > k ? j : k); } }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s1 = sc.nextLine(); String s2 = sc.nextLine(); sc.close(); boolean f = true; int len = s2.length(); for (int i = 0 ; i < len ; i++) { if(s1.indexOf(s2.substring(0, 1)) != -1) { s1 = s1.substring(s1.indexOf(s2.substring(0, 1))+1); s2 = s2.substring(1); } else { f = false; } } if(f) { System.out.println("yes"); } else { System.out.println("no"); } }
1,取子序列N2第一个字符找出在原始序列N1的第一个的位置索引号保存在res[],并且同时删除原始序列中 包括此位置之前的所有字符 2,继续第一步直道子序列查找完毕(中间出现子序列任何一个字符不存在于原始序列输出No结束) 3,将res升序排序后与原始res比较相等则输出Yes,否则输出No import sys N1=input() N2=input() def a(N1,N2): res=[] if N2 in N1: print('Yes') else: for i in N2: if(i in N1): n=N1.index(i) res+=[n] N1=N1[n+1:] else: print('No') return res1=res res.sort() if(res==res1): print('Yes') else: print('No') a(N1,N2)
var s=readline(); var t=readline(); var add=".*"; var str_reg=""; for(var i=0;i<t.length;i++){ if(/[.*+?()$^{}]/g.test(t[i])){ str_reg+=add+"\\"+t[i]; }else{ str_reg+=add+t[i]; } } str_reg=str_reg+add; var reg=new RegExp(str_reg,"g") if(reg.test(s)){ print("Yes"); }else{ print("No"); }
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s1 = scanner.nextLine(); String s2 = scanner.nextLine(); System.out.println(sub(s1, s2)); } public static String sub(String s1, String s2) { int i = 0,j = 0; int start = 0; while (start < s1.length()) { //s1从第start个元素开始找s2。因为子串可能从任意位置开始匹配 j = start; i = 0; //开始匹配 while (i < s2.length() && j < s1.length()) { if (s1.charAt(j) == s2.charAt(i)) { i++; j++; } else { j++; } } start ++; if (i == s2.length()) { return "Yes"; } } return "No"; } }