Re: Why having WA with UVa 10340- All in All
Posted: Wed Jul 16, 2014 2:11 pm
It will be good if always remove your code after getting accepted. 

Code: Select all
while (cin>>subkal>>kal){
Code: Select all
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
while(cin>>s>>t)
{
if(cin.eof())
return 0;
int temp=0,yes=1,j;
if(s.size()>t.size())
{
yes=0;
}
else if(s.size()==t.size())
{
if(s==t)
yes=1;
else
yes=0;
}
else
for(int i=0; s[i]; i++)
{
for(j=temp; t[j]; j++)
{
if(s[i]==t[j])
{
temp=j;
break;
}
else if(j==t.size()-1)
{
yes=0;
break;
}
}
// if(j==t.size() && temp)
// {
// yes=0;
// break;
// }
}
if(yes==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
Code: Select all
import sys
def findSubstr(s1, s2):
if(len(s2) == 0) or (len(s1) > len(s2)):
return False
elif s1[0] == s2[0] and len(s1) == 1:
return True
elif s1[0] == s2[0] and len(s1) > 1:
return findSubstr(s1[1:], s2[1:])
elif s1[0] != s2[0]:
return findSubstr(s1,s2[1:])
try:
while 1:
line = sys.stdin.readline()
inf = list(str(line).split())
s1 = inf[0]
s2 = inf[1]
res = 'Yes' if findSubstr(s1,s2) else 'No'
print(res)
except:
exit(0)