week6-NO.392.Is Subsequence

本文介绍了一个经典的编程问题:如何判断一个字符串是否为另一个字符串的子序列。子序列是指通过删除某些字符但保持其余字符相对顺序不变所形成的字符串。文章详细阐述了解决此问题的思路与实现方法。

题目

  • Total Accepted: 27326
  • Total Submissions: 61741
  • Difficulty: Medium
  • Contributor: LeetCode

Given a string s and a string t, check if s is subsequence of t.

You may assume that there is only lower case English letters in both s and tt is potentially a very long (length ~= 500,000) string, and s is a short string (<=100).

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ace" is a subsequence of "abcde" while "aec" is not).

Example 1:
s = "abc"t = "ahbgdc"

Return true.

Example 2:
s = "axc"t = "ahbgdc"

Return false.

https://leetcode.com/problems/is-subsequence/#/description

思路

题目需要判断字符串s是否是字符串t的子串。其中子串的定义是通过删除某些字符但不改变所有字符排列顺序的情况下能得到的字符串。

思路是对字符串s的每一个字符,依次在字符串t中进行查找,同时每次查找的开始位置是上一次查找的结束位置,以保证顺序性。

源程序

class Solution {
public:
    bool isSubsequence(string s, string t) {
        int l1 = s.size(),l2 = t.size();
        int i,j;
        j = 0;
        for(i = 0;i < l1;i ++){
            while(t[j] != s[i] && j < l2)
                j ++;
            if(j == l2)
                break;
            j ++;
        }
        if(i == l1)
            return true;
        else
            return false;
    }
};


分析并翻译下面英文文档内容:Operation The ftpAdapter searches a specific folder for files with an '.xml' or '.rdy' extension. When it finds an xml file, the file is renamed with an '.rdy' extension. When an '.rdy' file is found, an application event is sent to the BAP application specified. The name of the event is the same as the root node name. The event data is the complete contetts of the file. The file is then deleted. Config file A file adapterName.exe.config must exist to tell the application how to communicate with BAP. This file must reside in the same folder as the executable. The default config file is shown below. Only the name of the BAP application server (in red) needs to be changed. <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="DiscoveryUrl" value="http://pe-phoenix1:57151/CDiscovery.soap"></add> </appSettings> <system.runtime.remoting> <application> <service> <wellknown type="Brooks.ftpAdapter.MsgHandler, ftpAdapter" mode="Singleton" objectUri="ftpAdapter.soap" /> </service> <channels> <channel ref="http" port="64011"> <serverProviders> <provider ref="wsdl" /> <formatter ref="soap" typeFilterLevel="Full" /> <formatter ref="binary" typeFilterLevel="Full" /> </serverProviders> </channel> <channel ref="tcp" port="64012"> <serverProviders> <provider ref="wsdl" /> <formatter ref="soap" typeFilterLevel="Full" /> <formatter ref="binary" typeFilterLevel="Full" /> </serverProviders> </channel> </channels> </application> </system.runtime.remoting> </configuration> Configuring the Plug In Registration in the BAP Integration Editor Since the application adapter only sends messages to BAP and receives no commands, events or replies, only the application adapter name (line 1) in the Plug In Registration definition must be configured. All other fields should be left blank. In the events definitions section, the events must be defined as "From Application" and the event name and the root node name must be identical. The root node name is the Complex (list) item directly below the event name. This is required since the xml message does not have any information regarding the event name so this value will be used as the event name. The event definition must match exactly with the xml messages expected to be received. Command Line Arguments The ftpAdapter executable takes three optional command line arguments. The first argument is the path of the folder to search. The default folder is C:\xml. The second argument is the adapter name to send the events to. A configuration file must exist with this name plus .exe.config. The third command line argument is the delay, in milliseconds, between subsequent scans of the folder. The default is 5000. The minimum is 1000. Monitoring The ftpAdapter application writes several messages to a console window. The following is displayed during initialization. The first three lines show the command line arguments or defaults for them. Then the Starting message and the adapter configuration information. This information is useful to determine if the adapter is correctly configured. Adapter: adapterName Path: path ScanRate: nnnn Starting adapterName --------------------------------------------------------------- adapterName Address: http://10.36.254.87:64011/adapterName.soap BAP Discovery Address: http://pe-phoenix1:57151/CDiscovery.soap --------------------------------------------------------------- Dynamic messages displayed for each file found in the specified folder. nnn is a count of how many messages have been found and sent. renamed file 'path\file.xml' Sent event #nnn, eventName, to BAP XML message deleted file 'path\file.rdy' Error Messages The following exceptions are caught and a message is written to the console window. 1. exception parsing xml message The third argument must be a decimal number of milliseconds. If there are spaces in the path then it must be enclosed in quotes. 2. exception scanning directory path Verify that the path argument is correct and that the specified folder exists. 3. Exception Initializing: Verify that the adaptername.exe.config file exists and is correctly configured. This file must be in the default path of the executeable. 4. exception parsing xml message The message is parsed to determine the event name. The event used is the root node name. 5. Cmd From BAP, msg This adapter is not configured to accept commands from BAP. Logging All of the messages written to the Console window are also written to a log file. The log file is a text file with the named the current day of the week. It is written in the same folder specified in the path command line argument.
11-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值