JAVA 加密术

加密术

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

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

Input

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

Output

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

Sample Input

string  Strstring
HELLO  sdhfHqEiweqLbnLOqwerty
nomatter  nsomatstr
friend  FriEendly

Sample Output

Yes
Yes
No
No



import java.util.*;
class Number{
	String ch, ch1;

	public Number(String ch, String ch1) {
	
		this.ch = ch;
		this.ch1 = ch1;
	}
	public int number() {
		int count = 0;
		int i;
		int k = 0;
		for(i = 0; i < ch.length(); i++) {
			//从头遍历第一个字符串,在第二个字符串中找到一个字符的位置后,下一个字符从当前位置开始往后查找,这样就可以保证第一个字符串在第二个字符串中是顺序查找到的
			if(ch1.indexOf(ch.charAt(i), k) != -1) {
				count++;
				 k = ch1.indexOf(ch.charAt(i), k);
			 }
			else {
				break;
			}
		}
		return count;
	}
}
public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()) {
			String ch = cin.next()//读到空格结束;
			String ch1 = cin.next();
			Number a = new Number(ch, ch1);
			if(a.number() == ch.length()) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
   }
}






猜你喜欢

转载自blog.csdn.net/Joywss/article/details/79979924