10340 - All in All
Moderator: Board moderators
WA. What's wrong with my code?
[cpp]#include<stdio.h>
#include<string.h>
#define N 1000
char str1[N], str2[N];
long long i,j,len1,len2,no;
void main(void)
{
while(scanf("%s%s",&str1[0],&str2[0])==2)
{
len1 = strlen(str1);
len2 = strlen(str2);
i = j = no = 0;
if(len2<len1)
no = 1;
else
{
while(i<len1)
{
while(j<len2)
{
if(str2[j]==str1)
break;
j++;
}
if(j>=len2&&i<len1)
{
no = 1;
break;
}
i++;
}
}
if(no)
printf("No\n");
else
printf("Yes\n");
}
}[/cpp]

[cpp]#include<stdio.h>
#include<string.h>
#define N 1000
char str1[N], str2[N];
long long i,j,len1,len2,no;
void main(void)
{
while(scanf("%s%s",&str1[0],&str2[0])==2)
{
len1 = strlen(str1);
len2 = strlen(str2);
i = j = no = 0;
if(len2<len1)
no = 1;
else
{
while(i<len1)
{
while(j<len2)
{
if(str2[j]==str1)
break;
j++;
}
if(j>=len2&&i<len1)
{
no = 1;
break;
}
i++;
}
}
if(no)
printf("No\n");
else
printf("Yes\n");
}
}[/cpp]
10340 RTE
why is my code resulting RTE (SISVG)?
[c]#include<stdio.h>
#include<string.h>
void main()
{
char a[10000];
char b[10000];
int i,j;
int len;
while(scanf("%s %s",a,b)!=EOF)
{
j=0;
len=strlen(a);
for(i=0;b!='\0';i++)
{
if(j==len)
{
break;
}
if(b==a[j])
{
j++;
}
}
if(j==len)
printf("Yes\n");
else
printf("No\n");
}
}[/c]
don't know why....
[c]#include<stdio.h>
#include<string.h>
void main()
{
char a[10000];
char b[10000];
int i,j;
int len;
while(scanf("%s %s",a,b)!=EOF)
{
j=0;
len=strlen(a);
for(i=0;b!='\0';i++)
{
if(j==len)
{
break;
}
if(b==a[j])
{
j++;
}
}
if(j==len)
printf("Yes\n");
else
printf("No\n");
}
}[/c]
don't know why....
Code: Select all
char [100000]
10340 why my code is slower
the problem is Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s.
Sample Input
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter
Sample Output
Yes
No
Yes
No
my code is
[cpp]
#include "iostream.h"
#include "string.h"
int main(int argc, char* argv[])
{
long long lo,loop1,loop2,flag;
char a[100000],b[100000];
while(cin>>a>>b)
{
if(strlen(a)>strlen(b))
{
cout<<"No"<<endl;
continue;
}
lo=0;
for(loop1=0;loop1<strlen(a);loop1++)
{
flag=0;
for(loop2=lo;loop2<strlen(b);loop2++)
{
if(b[loop2]==a[loop1])
{
flag=1;
lo=loop2+1;
break;
}
}
if(flag==0)
{
cout<<"No"<<endl;
break;
}
}
if(flag==1) cout<<"Yes"<<endl;
}
return 0;
}
[/cpp]
which got TLE
and there's someone else's code which can be AC and only use 0.001 second:
[cpp]
#include<stdio.h>
#include<string.h>
void main()
{
char a[100000];
char b[100000];
int i,j;
int len;
while(scanf("%s %s",a,b)!=EOF)
{
j=0;
len=strlen(a);
for(i=0;b!='\0';i++)
{
if(j==len)
{
break;
}
if(b==a[j])
{
j++;
}
}
if(j==len)
printf("Yes\n");
else
printf("No\n");
}
}
[/cpp]
i know i used tow "for" loop but i still think my code will spend the same time,because our algorithm seems the same:(
anyone who can tell me why mine is slower?
Sample Input
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter
Sample Output
Yes
No
Yes
No
my code is
[cpp]
#include "iostream.h"
#include "string.h"
int main(int argc, char* argv[])
{
long long lo,loop1,loop2,flag;
char a[100000],b[100000];
while(cin>>a>>b)
{
if(strlen(a)>strlen(b))
{
cout<<"No"<<endl;
continue;
}
lo=0;
for(loop1=0;loop1<strlen(a);loop1++)
{
flag=0;
for(loop2=lo;loop2<strlen(b);loop2++)
{
if(b[loop2]==a[loop1])
{
flag=1;
lo=loop2+1;
break;
}
}
if(flag==0)
{
cout<<"No"<<endl;
break;
}
}
if(flag==1) cout<<"Yes"<<endl;
}
return 0;
}
[/cpp]
which got TLE
and there's someone else's code which can be AC and only use 0.001 second:
[cpp]
#include<stdio.h>
#include<string.h>
void main()
{
char a[100000];
char b[100000];
int i,j;
int len;
while(scanf("%s %s",a,b)!=EOF)
{
j=0;
len=strlen(a);
for(i=0;b!='\0';i++)
{
if(j==len)
{
break;
}
if(b==a[j])
{
j++;
}
}
if(j==len)
printf("Yes\n");
else
printf("No\n");
}
}
[/cpp]
i know i used tow "for" loop but i still think my code will spend the same time,because our algorithm seems the same:(
anyone who can tell me why mine is slower?
"Learning without thought is useless;thought without learning is dangerous."
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
"Hold what you really know and tell what you do not know -this will lead to knowledge."-Confucius
-
- New poster
- Posts: 2
- Joined: Mon May 17, 2004 9:36 pm
10340 why RTE?

Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char * s = (char *)malloc(sizeof(char));
char * t = (char *)malloc(sizeof(char));
int i, tam, pos;
char c;
while (scanf("%s %s", s, t) != EOF){
tam = strlen(s);
pos = 0;
for (i=0; i<tam; i++){
c = s[i];
while ((t[pos])&&(t[pos] != c))
pos++;
}
if (t[pos])
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
-
- New poster
- Posts: 32
- Joined: Thu Jul 31, 2003 6:21 am
- Location: Daffodil Univ, Bangladesh
- Contact:
You Have to use at least char array size of 1000000.
Use long as variable instead of int
Because pointer doesn't support that size.
Then u will not got RTE.
Use long as variable instead of int
Because pointer doesn't support that size.
Then u will not got RTE.
Hate WA
Visit phpBB!
Visit phpBB!
-
- New poster
- Posts: 2
- Joined: Mon May 17, 2004 9:36 pm
-
- New poster
- Posts: 32
- Joined: Thu Jul 31, 2003 6:21 am
- Location: Daffodil Univ, Bangladesh
- Contact:
Try this input:
abbbbc abccccccccccc
Output:
No
But Yours is Yes.
Fix this, Then u will may got AC.
For further help you can mail me with ur code at:
nazmul_acm@yahoo.com
Wish u best of luck.
abbbbc abccccccccccc
Output:
No
But Yours is Yes.
Fix this, Then u will may got AC.
For further help you can mail me with ur code at:
nazmul_acm@yahoo.com
Wish u best of luck.
Hate WA
Visit phpBB!
Visit phpBB!