Java练习 SDUT-2787_加密术

加密术

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.*;

public class Main {
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        node a;
        while(cin.hasNext())
        {
            a = new node(cin.next(),cin.next());
            if(a.judge()==1)
                System.out.println("Yes");
            else
                System.out.println("No");
        }
        cin.close();
    }
}

class node
{
    String a,b;
    node(String a,String b)
    {
        this.a = a;
        this.b = b;
    }
    int judge()
    {
        int i,j,f = 1,num = 0;
        j = 0;
        for(i=0;i<a.length()&&f==1;i++)
        {
            if(j==b.length())
                break;
            for(;j<b.length();j++)
            {
                if(a.charAt(i)==b.charAt(j))
                {
                    j++;
                    num ++;
                    break;
                }
            }
        }
        if(num!=a.length())
            f = 0;
        return f;
    }
}

猜你喜欢

转载自www.cnblogs.com/luoxiaoyi/p/9973255.html