SDUT 2787 加密术

版权声明:iQXQZX https://blog.csdn.net/Cherishlife_/article/details/86515412

加密术

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic Discuss

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

Hint

Source

pyn

SDUTOJ   JAVA加上注释   会出现 编译错误

学到的内容;

String.indexOf()的 用法   文档: http://www.runoob.com/java/java-string-indexof.html 

indexOf() 方法有以下四种形式:

  • public int indexOf(int ch): 返回指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。

  • public int indexOf(int ch, int fromIndex): 返回从 fromIndex 位置开始查找指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。

  • int indexOf(String str): 返回指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。

  • int indexOf(String str, int fromIndex): 返回从 fromIndex 位置开始查找指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。

实例:  

public class Test {
    public static void main(String args[]) {
        String Str = new String("菜鸟教程:www.runoob.com");
        String SubStr1 = new String("runoob");
        String SubStr2 = new String("com");
 
        System.out.print("查找字符 o 第一次出现的位置 :" );
        System.out.println(Str.indexOf( 'o' ));
        System.out.print("从第14个位置查找字符 o 第一次出现的位置 :" );
        System.out.println(Str.indexOf( 'o', 14 ));
        System.out.print("子字符串 SubStr1 第一次出现的位置:" );
        System.out.println( Str.indexOf( SubStr1 ));
        System.out.print("从第十五个位置开始搜索子字符串 SubStr1 第一次出现的位置 :" );
        System.out.println( Str.indexOf( SubStr1, 15 ));
        System.out.print("子字符串 SubStr2 第一次出现的位置 :" );
        System.out.println(Str.indexOf( SubStr2 ));
    }
}

ACcode: 

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String s1 = in.next();
            String s2 = in.next();
            int len1 = s1.length();
            int flag = 0, cnt = 0;
            for (int i = 0; i < len1; i++) {
                flag = s2.indexOf(s1.charAt(i), flag); // 如果上次搜索到 将从上一个flag  开始搜
                if (flag == -1)
                    break;
                else
                    cnt++;
            }
            if (cnt == s1.length())
                System.out.println("Yes");
            else
                System.out.println("No");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/Cherishlife_/article/details/86515412