codechef+Your Name is Mine
2013-05-05 14:12
183 查看
Your Name is MineProblem code: NAME2 | Submit My Submissions All Submissions |
A man with name M is allowed to marry a woman with nameW, only if
M is a subsequence of
W or W is a subsequence of M.
A is said to be a subsequence of B, ifA can be obtained by deleting some elements of
B without changing the order of the remaining elements.
Your task is to determine whether a couple is allowed to marry or not, according to Archer's rule.
Input
The first line contains an integer T, the number of test cases.T test cases follow. Each test case contains two space separated stringsM and
W.
Output
For each test case print
"YES"if they are allowed to marry, else print
"NO". (quotes are meant for clarity, please don't print them)
Constraints
1 ≤ T ≤ 100
1 ≤ |M|, |W| ≤ 25000 (|A| denotes the length of the string A.)
All names consist of lowercase English letters only.
Example
Input:3john johannaira irakayla jaylaOutput:YESYESNO
Explanation
Case 1: Consider S = "johanna". So,S[0] = 'j', S[1] = 'o', S[2] = 'h' and so on. If we remove the indices [3, 4, 6] or [3, 5, 6] from S, it becomes"john".
Hence "john" is a subsequence of S, so the answer is "YES".
Case 2: Any string is a subsequence of it self, as it is formed after removing"0" characters. Hence the answer is
"YES".
Case 3: "jayla" can not be attained from"kayla" as removing any character from
"kayla" would make the string length smaller than"jayla", also there is no
'j' in "kayla". Similar reasoning can be applied to see why"kayla" can't be attained from
"jayla". Hence the answer is "NO".
/* 题目大意:给你两个字符串,要求你求一个字符串删掉某些字符(不改变原有的顺序), 能否等于另一个字符串,简单说就是经过删除变形后能否包含另一个字符串 思路:直接遍历 */ #include<iostream> using namespace std; int main() { int t; cin>>t; while(t--){ char a[25003],b[25003],c[25003]; cin>>a>>b; int k=0,i; int lena=strlen(a),lenb=strlen(b); if(lena<lenb) { memcpy(c,a,lena+1); memcpy(a,b,lenb+1); memcpy(b,c,lena+1); } lena=strlen(a); lenb=strlen(b); for(i=0;i<lena;i++) if(a[i]==b[k]) k++; if(k==lenb) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- [笔记] How to get the versionCode and versionName of your app
- 'Source code for your Pod was not accessible to CocoaPods Trunk. Is it a private repo or behind a us
- 每日一句:Your guess is as good as mine
- 强人对初中英文课本的解析(很有道理的说,让我们一起说what is your name)
- Codeforces Is your horseshoe on the other hoof?
- 二分图匹配:what is in your name
- 输入三个字符串,允许有空格,输出最大公共子串 例如输入: what your name my name is ABC
- Share your mind, maybe is better than share your code
- HOWTO:Turn Off PDA Display while your application is running.(VB.Net/c#+.Net CF+PPC2003) from CodeProject
- Your Job Is Not to Write Code
- codechef+Name Reduction
- This is the first problem for test. Since all we know the ASCII code, your job is simple: Input numb
- Your name is mud. 声名狼藉
- Xcode编译错误 Code Sign error: The identity 'iPhone Developer: Your Name' doesn't match any valid certif
- The call to LoadLibrary(YourExtensionName) failed, Win32 error 0n14001, “This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.”
- This event supports the .NET Framework infrastructure and is not intended to be used directly from your code?继承自VScrollbar的自定义winform控件,某些事件不触发的问题(Winform控件开发学习)
- talk is expensive , Don't show me your code at that time
- google code jam exercise——Your Rank Is Pure
- Codechef It Is Axis Time
- TypeName of CA1505 is AvoidUnmaintainableCode, not AvoidUnmantainableCode.