Is that still true as of now? I guess we have to first change any non a-zA-Z to 'a' huh?Yes, I also found out that there exists other characters in the input.
My program handles all invalid input characters as if they are 'a' (of course not intentionally, only because it assumes that only valid characters occur).
10679 - I Love Strings!!
Moderator: Board moderators
-
- Learning poster
- Posts: 98
- Joined: Sat Jan 21, 2006 12:45 pm
- Location: Busan,Corea(Republic of)
10679 WHY AC!!! I'm CRAZY!!!!!!!
#include<iostream.h>
#include<string.h>
int main(){
char a[100001],b[100001];
int k,i,j,c,d;
cin >> c;
for(i=0;i<c;i++){
cin.get();
cin >> a;
cin >> d;
cin.get();
for(j=0;j<d;j++){
cin >> b;
int sw=0,len=strlen(a),z=0,len2=strlen(b);
for(k=0;;k++){
if(sw==len2)
break;
if(b[sw]==a[z]){
sw++;
z++;
}
else{
z++;
sw=0;
}
if(z==len2)
break;
}
if(sw==len2)
cout << "y" << endl;
else
cout << "n" << endl;
}
}
return 0;
}
THIS IS WHY AC?
IT'S WRONG!
#include<string.h>
int main(){
char a[100001],b[100001];
int k,i,j,c,d;
cin >> c;
for(i=0;i<c;i++){
cin.get();
cin >> a;
cin >> d;
cin.get();
for(j=0;j<d;j++){
cin >> b;
int sw=0,len=strlen(a),z=0,len2=strlen(b);
for(k=0;;k++){
if(sw==len2)
break;
if(b[sw]==a[z]){
sw++;
z++;
}
else{
z++;
sw=0;
}
if(z==len2)
break;
}
if(sw==len2)
cout << "y" << endl;
else
cout << "n" << endl;
}
}
return 0;
}
THIS IS WHY AC?
IT'S WRONG!
Archaan
CAN YOU BEAT ME?
http://acm.uva.es/problemset/usersjudge.php?user=19788
AND,
http://acm.uva.es/problemset/submit.php
http://online-judge.uva.es/problemset/submit.php
SUBMIT AND GET AC!!!
CAN YOU BEAT ME?
http://acm.uva.es/problemset/usersjudge.php?user=19788
AND,
http://acm.uva.es/problemset/submit.php
http://online-judge.uva.es/problemset/submit.php
SUBMIT AND GET AC!!!
-
- Learning poster
- Posts: 98
- Joined: Sat Jan 21, 2006 12:45 pm
- Location: Busan,Corea(Republic of)
SEE MY CODE. IT's AC AND I'M GETTING CRAZY...
#include<iostream.h>
#include<string.h>
int main(){
char a[100001],b[100001];
int k,i,j,c,d;
cin >> c;
for(i=0;i<c;i++){
cin.get();
cin >> a;
cin >> d;
cin.get();
for(j=0;j<d;j++){
cin >> b;
int sw=0,len=strlen(a),z=0,len2=strlen(b);
for(k=0;;k++){
if(sw==len2)
break;
if(b[sw]==a[z]){
sw++;
z++;
}
else{
z++;
sw=0;
}
if(z==len2)
break;
}
if(sw==len2)
cout << "y" << endl;
else
cout << "n" << endl;
}
}
return 0;
}
THIS IS WHY AC?
IT'S WRONG!
#include<iostream.h>
#include<string.h>
int main(){
char a[100001],b[100001];
int k,i,j,c,d;
cin >> c;
for(i=0;i<c;i++){
cin.get();
cin >> a;
cin >> d;
cin.get();
for(j=0;j<d;j++){
cin >> b;
int sw=0,len=strlen(a),z=0,len2=strlen(b);
for(k=0;;k++){
if(sw==len2)
break;
if(b[sw]==a[z]){
sw++;
z++;
}
else{
z++;
sw=0;
}
if(z==len2)
break;
}
if(sw==len2)
cout << "y" << endl;
else
cout << "n" << endl;
}
}
return 0;
}
THIS IS WHY AC?
IT'S WRONG!
Archaan
CAN YOU BEAT ME?
http://acm.uva.es/problemset/usersjudge.php?user=19788
AND,
http://acm.uva.es/problemset/submit.php
http://online-judge.uva.es/problemset/submit.php
SUBMIT AND GET AC!!!
CAN YOU BEAT ME?
http://acm.uva.es/problemset/usersjudge.php?user=19788
AND,
http://acm.uva.es/problemset/submit.php
http://online-judge.uva.es/problemset/submit.php
SUBMIT AND GET AC!!!
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Just a few simple rules to keep the forums usable for everybody:
- use code tags, so it's easier for others to read your code;
- don't post accepted code;
- don't just dump your code, but explain your problem;
- don't post the same posting in more than one thread, it clutters the forum.
- use code tags, so it's easier for others to read your code;
- don't post accepted code;
- don't just dump your code, but explain your problem;
- don't post the same posting in more than one thread, it clutters the forum.
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.
-
- Learning poster
- Posts: 98
- Joined: Sat Jan 21, 2006 12:45 pm
- Location: Busan,Corea(Republic of)
Thanks for your advice. I'll remember your advices in my heart every time from now.
Archaan
CAN YOU BEAT ME?
http://acm.uva.es/problemset/usersjudge.php?user=19788
AND,
http://acm.uva.es/problemset/submit.php
http://online-judge.uva.es/problemset/submit.php
SUBMIT AND GET AC!!!
CAN YOU BEAT ME?
http://acm.uva.es/problemset/usersjudge.php?user=19788
AND,
http://acm.uva.es/problemset/submit.php
http://online-judge.uva.es/problemset/submit.php
SUBMIT AND GET AC!!!
-
- New poster
- Posts: 2
- Joined: Tue Jul 04, 2006 2:28 pm
- Location: CSE-SUST-Bangladesh
10679 why TLE?
Code: Select all
//TLE
#include<stdio.h>
#include<string.h>
char S[100050],T[1050],*p,c;
long q,k,i,j;
void main()
{
//what is the problem
scanf("%ld",&k);//test case=k
for(i=0;i<k;i++)
{
scanf(" %s",S);
scanf(" %ld",&q);
for(j = 0;j<q;j++)
{
scanf(" %s",T);
p = strstr(S,T);
if(p)
printf("y\n");
else
printf("n\n");
}
}
}
zakaria
-
- New poster
- Posts: 3
- Joined: Tue May 24, 2005 10:58 pm
Why WA
Why WA?
I dont know. Anybody can help me ?
thanks.
#include<iostream>
#include<string>
using namespace std;
main()
{
char frase[100000],text[1000];
string output;
int casos,x,query,y,stat;
output="";
cin>>casos;
stat=0;
for(x=1;x<=casos;x++)
{
cin>>frase;
cin>>query;
if(query<1000)
{
for(y=1;y<=query;y++)
{
cin>>text;
if(strstr(frase,text)&& frase[1]==text[1])
{
if(stat==0)
stat=1;
else
output+="\n";
output+="y";
}
else
{
if(stat==0)
stat=1;
else
output+="\n";
output+="n";
}
}
}
}
cout << output;
}
I dont know. Anybody can help me ?
thanks.
#include<iostream>
#include<string>
using namespace std;
main()
{
char frase[100000],text[1000];
string output;
int casos,x,query,y,stat;
output="";
cin>>casos;
stat=0;
for(x=1;x<=casos;x++)
{
cin>>frase;
cin>>query;
if(query<1000)
{
for(y=1;y<=query;y++)
{
cin>>text;
if(strstr(frase,text)&& frase[1]==text[1])
{
if(stat==0)
stat=1;
else
output+="\n";
output+="y";
}
else
{
if(stat==0)
stat=1;
else
output+="\n";
output+="n";
}
}
}
}
cout << output;
}
10679 WA
Hi guys,
i have made an easy code in java for this problem, but i got WA, does anybody have any test cases for it? Or find a problem with my code?
My code is here:
i have made an easy code in java for this problem, but i got WA, does anybody have any test cases for it? Or find a problem with my code?
My code is here:
Code: Select all
import java.io.IOException;
class Main {
static String ReadLn(int maxLg) // utility function to read from stdin
{
byte lin[] = new byte[maxLg];
int lg = 0, car = -1;
try {
while (lg < maxLg) {
car = System.in.read();
if ((car < 0) || (car == ' ') || (car == '\n'))
break;
lin[lg++] += car;
}
} catch (IOException e) {
return (null);
}
if ((car < 0) && (lg == 0))
return (null); // eof
return (new String(lin, 0, lg));
}
public static void main(String[] args) {
Main d = new Main();
d.begin();
}
void begin(){
int num = Integer.parseInt(ReadLn(255));
for (int i = 0;i<num;i++){
String s = ReadLn(255);
int q = Integer.parseInt(ReadLn(255));
for (int j = 0;j<q;j++){
String query = ReadLn(255);
if (s.indexOf(query)>=0)
System.out.println("y");
else
System.out.println("n");
}
}
}
}
My KMP failed with TLE. So, whats the trick?? any optimization upon the KMP or any new algorithm . I found Krugel and Sajjad bhai suggested two different new algorithm . But The r not assymtotically faster than KMP. Infact according to Cormen, KMP is the optimal algorithm for String matching. Is there any critical input that just makes the KMP fool and passes for any other algo??
my code here :
my code here :
Code: Select all
#include<cstdio>
#include<iostream>
#include<cstring>
#define KMP_PATTERN_MAX 10005
using namespace std;
int Failure[KMP_PATTERN_MAX];
void failure_function(char* P)
{
register int m=strlen(P);
Failure[0]=0;
register int i=1;
register int j=0;
register int l=strlen(P);
while(i<l)
{
if(P[i]==P[j])
{
Failure[i]=j+1;
i++;
j++;
}
else if(j>0)
{
j=Failure[j-1];
}
else
{
Failure[i]=0;
i=i+1;
}
}
return;
}
int KMP_MATCH(char* T, char* P)
{
register int n=strlen(T);
register int m=strlen(P);
failure_function(P);
int i=0,j=0;
while(i<n)
{
if(P[j]==T[i])
{
if(j==(m-1))
{
return (i-j);
}
i++;
j++;
}
else if(j>0)
{
j=Failure[j-1];
}
else
{
i++;
}
}
return -1;
}
int main(void)
{
char T[100009],P[1009];
register int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%s",&T);
scanf("%d",&n);
while(n--)
{
scanf("%s",&P);
if(KMP_MATCH(T,P)>=0)
{
printf("y\n");
}
else
{
printf("n\n");
}
}
}
return 0;
}
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
CSE,BUET
Bangladesh
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
TLE 10679 - I love Strings!!!
Hmm i think this problem cant be solved by KMP.
Last edited by newton on Sun Sep 07, 2008 1:07 pm, edited 1 time in total.