SDUT-oj 加密术

来源:互联网 发布:打印设置软件 编辑:程序博客网 时间:2024/05/17 17:17
 

加密术

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

加密技术是一种常用的安全保密手段,利用加密技术可以把重要的数据变成经过加密变成乱码传送,到达目的地后再利用解密手段还原。现在我们发明了一种新的加密技术,即通过在一个字符串的任意位置插入若干个随机生成的字符(‘a’~’z’或’A’~’Z’)对该字符串加密。
我们想要申请专利,但在这之前,需要做大量的检测。所以有必要编写一个程序判断加密后的字符串经过解密是否是加密前的字符串,即从加密后的字符串中删除若干个字符后剩下的字符串是否可以拼接成加密前的字符串。Can you help us ?

Input

输入包含多组,每组输入两个串(只包含大小写字母)S,T,中间用空格分开。S和T的长度不超过100000。

Output

对于每组输入,如果加密后的字符串解密后与加密前的字符串相同输出“Yes”,否则输出“No”。

Example Input

string  StrstringHELLO  sdhfHqEiweqLbnLOqwertynomatter  nsomatstrfriend  FriEendly

Example Output

YesYesNoNo

Hint

 

做法一:

import java.util.Scanner;public class Main {public static void main(String[] args){Scanner p = new Scanner(System.in);while(p.hasNext()){String str1 = p.next() ;String str2 = p.next() ; int i = 0 ;int f = 0 ; while(i<str1.length()){f = str2.indexOf(str1.charAt(i),f); if(f!=-1){i++;}else if(f==-1){break ; }}if(i==str1.length()){System.out.println("Yes");}else{System.out.println("No");}}}}


做法二:

import java.util.Scanner;public class Main {public static void main(String[] args){Scanner p = new Scanner(System.in);while(p.hasNext()){String str1 = p.next() ;String str2 = p.next() ;     int key = 0 ;int j ;int num = 0 ;for(int i=0;i<str1.length();i++){int flag = 0 ;for(j=key;j<str2.length();j++){if(str1.charAt(i)==str2.charAt(j)){key = j + 1 ;flag=1;num++;break ;}}}if(num==str1.length()){System.out.println("Yes");}else{System.out.println("No");}}}}