zoukankan      html  css  js  c++  java
  • poj 1936 All In All

    All in All
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 31536   Accepted: 13070

    Description

    You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string. 

    Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s. 

    Input

    The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace.The length of s and t will no more than 100000.

    Output

    For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

    Sample Input

    sequence subsequence
    person compression
    VERDI vivaVittorioEmanueleReDiItalia
    caseDoesMatter CaseDoesMatter
    

    Sample Output

    Yes
    No
    Yes
    No
    

    Java AC 代码:

    import java.util.Scanner;
    
    public class Main {
        
        public static void main(String[] args) {
            String s = "";
            String t = "";
            Scanner sc = new Scanner(System.in);
            int sIndex = 0;
            int tIndex = 0;
            while((s = sc.next()) != "" && (t = sc.next()) != "") {
                
                if(s.length() > t.length()) {
                    System.out.println("No");
                    continue;
                }
                int sLen = s.length();
                int tLen = t.length();
                while(sIndex < sLen && tIndex < tLen) {
                    if(s.substring(sIndex, sIndex + 1).equals(t.substring(tIndex, tIndex + 1))) {
                        sIndex ++;
                    }
                    tIndex ++;
                }
                if(sIndex == sLen)
                    System.out.println("Yes");
                else 
                    System.out.println("No");
                sIndex = 0;
                tIndex = 0;
            }
            
        }
    }
  • 相关阅读:
    Linux如何对文件内容中的关键字进行查找
    Gitlab如何进行备份恢复与迁移?
    Centos7上传文件和下载文件命令
    Linux下如何查看系统启动时间和运行时间
    您应该知道的35个绝对重要的Linux命令
    rabbitMq可靠消息投递之交换机备份
    rabbitMq可靠性投递之配置(消息至交换机,至队列不通的回调)
    springcloud超时重试机制的先后顺序
    mysql 8.0 1405的坑
    linux安装mysql8.0
  • 原文地址:https://www.cnblogs.com/kkkkkk/p/5546153.html
Copyright © 2011-2022 走看看