InsertZ

Problem Statement

 

You are given two strings: init and goal. Both init and goal contain lowercase letters only. Additionally, init does not contain the character 'z'.

Your goal is to transform init into goal. The only operation you are allowed to do is to insert the character 'z' anywhere into init. You can repeat the operation as many times as you want, and each time you can choose any position where to insert the 'z'.

For example, if init="fox", you can transform it to "fzox" in one operation. Alternately, you can transform "fox" into "zzzfoxzzz" in six operations. It is not possible to transform "fox" into any of the strings "fx", "foz", "fxo", "foxy".

Return "Yes" (quotes for clarity) if it is possible to transform init into goal. Otherwise, return "No".

Definition

 
Class:InsertZ
Method:canTransform
Parameters:string, string
Returns:string
Method signature:string canTransform(string init, string goal)
(be sure your method is public)
 
 

Notes

-Note that the return value is case sensitive.

Constraints

-init and goal will each contain between 1 and 50 characters, inclusive.
-Each character of init and goal will be a lowercase letter ('a'-'z').
-init will not contain the letter 'z'.

Examples

0) 
 
"fox"
"fozx"
Returns: "Yes"
By inserting 'z' to the position bettween 'o' and 'x' in "fox", we obtain "fozx".
1) 
 
"fox"
"zfzoxzz"
Returns: "Yes"
You may perform the operation multiple times.
2) 
 
"foon"
"foon"
Returns: "Yes"
In this case init and goal are equal. You do not have to perform the operation.
3) 
 
"topcoder"
"zopzoder"
Returns: "No"
4) 
 
"aaaaaaaaaa"
"a"
Returns: "No"
5) 
 
"mvixrdnrpxowkasufnvxaq"
"mvizzxzzzrdzznzrpxozzwzzkazzzszzuzzfnvxzzzazzq"
Returns: "Yes"
6) 
 
"opdlfmvuicjsierjowdvnx"
"zzopzdlfmvzuicjzzsizzeijzowvznxzz"
Returns: "No"

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.     

这不是吧Z删了就好了!!!




class InsertZ {
public:
string canTransform(string, string);
};


string InsertZ::canTransform(string init, string goal) {
string s;
for(int i=0;i<goal.size();i++){
if(goal[i]!='z')
s+=goal[i];



}


if(s==init)
return "Yes";
else
return "No";
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值