← Back to topics
Topic

MoreStrings

A
Al3kSaNdaR
Can someone tell me what is wrong ? I get 2 WAs :(

http://www.z-trening.com/new/www/html/submit.php?submit=7100050008&subm_code=1
D
Daniel93
Look how I do it, its very easy,

#include<iostream>
using namespace std;

int main()
{
string a,b,c;
cin >> a >> b >> c;

int idxA=0, idxB=0;
int lenA=0, lenB=0;

for(int i=0;i<c.length();i++)
{
if( c[i] == a[idxA] ){
lenA++; idxA++;
}
if( c[i] == b[idxB] ){
lenB++; idxB++;
}
}

if( lenB != b.length() || lenA != a.length() )cout<<"no"<<endl;
else cout<<"yes"<<endl;

return 0;
}
A
Al3kSaNdaR
Heh :) Thanks, I thought only about recursion. :(
h
halil
Nice solution, but variables "lenA" and "lenB" are unnecessary.
H
Hristijan
Isn't this code wrong?!?!?!?! I posted it and it didn't give me wrong result but I made my own example. Caaaaa Cbbbbb CC. Here the output should be yes but it outputs no. Btw I was also trying to solve it using recursion.
h
halil
I think that output should be no (in this case).
H
Hristijan
Yea my bad :D I didn't read the text correctly. I thought that you dont have to use all chars from one string.