10129 - Play on Words
Moderator: Board moderators
10129 - Play on Words
I think its simple Euler tour testing .
but getting wrong answer.....
but getting wrong answer.....
-
- Learning poster
- Posts: 83
- Joined: Wed Feb 27, 2002 2:00 am
- Location: Taiwan
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
10129 - Play on words
I think this is an easy problem where all I need to do is to detect the presence of an euler path in a directed graph. But I am getting repeated WA
for apparantly no reason. Can someone give me some tricky I/O please? Thanks in advance.

You should never take more than you give in the circle of life.
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
-
- Experienced poster
- Posts: 154
- Joined: Sat Apr 17, 2004 9:34 am
- Location: EEE, BUET
-
- New poster
- Posts: 2
- Joined: Fri Jan 21, 2005 9:07 pm
10129 Play on Words WA
Here is my code, why do I always get wrong answer?
Where is my problem?
#include <stdio.h>
4 #include <stdlib.h>
5
6 int main(int argc, char **argv)
7 {
8 long long t, n;
9 int i, j, ctn, flag;
10 char c, link;
11 char *check;
12 check=(char *)malloc(sizeof(char)*1001);
13
14 scanf("%lld%c", &t, &c);
15 for(i=0; i<t; i++){
16 scanf("%lld%c", &n, &c);
17 if(n<1 || n>100000)
18 return 0;
19 flag=1;
20 for(j=0; j<n; j++){
21 ctn=0;
22 while((c=getchar())!='\n'){
23 if(c==EOF)
24 return 0;
25 check[ctn]=c;
26 ctn++;
27 }
28 check[ctn]='\0';
29 if(ctn<2 || ctn>1000)
30 return 0;
31
32 if(j>0){
33 if(check[0]!=link)
34 flag=0;
35 }
36
37 link = check[ctn-1];
38 }
39 if(flag==1)
40 printf("Ordering is possible.\n");
41 else
42 printf("The door cannot be opened.\n");
43 }
44 return 0;
45 }
Where is my problem?
#include <stdio.h>
4 #include <stdlib.h>
5
6 int main(int argc, char **argv)
7 {
8 long long t, n;
9 int i, j, ctn, flag;
10 char c, link;
11 char *check;
12 check=(char *)malloc(sizeof(char)*1001);
13
14 scanf("%lld%c", &t, &c);
15 for(i=0; i<t; i++){
16 scanf("%lld%c", &n, &c);
17 if(n<1 || n>100000)
18 return 0;
19 flag=1;
20 for(j=0; j<n; j++){
21 ctn=0;
22 while((c=getchar())!='\n'){
23 if(c==EOF)
24 return 0;
25 check[ctn]=c;
26 ctn++;
27 }
28 check[ctn]='\0';
29 if(ctn<2 || ctn>1000)
30 return 0;
31
32 if(j>0){
33 if(check[0]!=link)
34 flag=0;
35 }
36
37 link = check[ctn-1];
38 }
39 if(flag==1)
40 printf("Ordering is possible.\n");
41 else
42 printf("The door cannot be opened.\n");
43 }
44 return 0;
45 }
You have wrong understanding on the problem.
It is asked "whether it is possible to arrange all of the plates in a sequence"
You can arrange the order of word, so for
2
abc
xxa
The answer is "possible".
It is asked "whether it is possible to arrange all of the plates in a sequence"
You can arrange the order of word, so for
2
abc
xxa
The answer is "possible".
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
10129-SEGMENTATION FAULT
All the variable and array are well defined
no pointer is used
why segmentation fualt?.............orz
THZ for any reply
no pointer is used
why segmentation fualt?.............orz
THZ for any reply
There are many ways to get segmentation fault.
Although you say array are well defined, how do you ensure that without knowing judge input?
In my opinion, there is only one way to ensure it, when you access any array, say a, you check if i < 0 or i > max. bound, if yes, then you crash the program by i = 1 / 0 (floating point error)
Always check your program with boundray case, for either N = 1 or 100000, you have to check if your program can passes such case by TESTING. Don't just read your code and then think it will pass.
Some other way of segmentation fault is "stack overflow". Say for this C program:
The endless recursion will get stack overflow and give you segmentation fault. Check if your program will get endless recursion.
Although you say array are well defined, how do you ensure that without knowing judge input?
In my opinion, there is only one way to ensure it, when you access any array, say a, you check if i < 0 or i > max. bound, if yes, then you crash the program by i = 1 / 0 (floating point error)
Always check your program with boundray case, for either N = 1 or 100000, you have to check if your program can passes such case by TESTING. Don't just read your code and then think it will pass.
Some other way of segmentation fault is "stack overflow". Say for this C program:
Code: Select all
re() {
int i;
re();
}
main() {
re();
}
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
Code: Select all
#include <stdio.h>
#include <string.h>
main(void)
{
char in[1000];
int head[26];
int tail[26];
int con[26][26];
int check[26];
int g[3];
int n=0;
int a,b,i,j,m,t,count,p,q;
int s=0;
int cb=0;
char prichk='0';
char secchk='0';
char terchk='0';
char finalchk='0';
char finalchk2='0';
char netio='0';
scanf ("%d\n" ,&t);
for (m=0;m<t;m++)
{
for (b=0;b<27;b++)
{
head[b]=0;
tail[b]=0;
check[b]=0;
}
printf("%d%d%d\n",head[26],tail[26],check[26]);
for (b=0;b<27;b++)
{
for (a=0;a<27;a++)
{
con[b][a]=0;
}
}
g[0]=-1;
g[1]=-1;
g[2]=0;
scanf ("%d\n" ,&s);
for (count=0;count<s;count++)
{
gets (in);
n = strlen(in);
-SKIP-
}
}
return 0;
}
I SEEMS NO PROBLEM......OTZ
CERTAINLY IT HAS PROBLEM!akiha wrote:Code: Select all
#include <stdio.h> int head[26]; int tail[26]; int con[26][26]; int check[26]; for (b=0;b<27;b++) { head[b]=0; tail[b]=0; check[b]=0; } printf("%d%d%d\n",head[26],tail[26],check[26]);
for "int tail[26]", the elements are numbered from 0 to 25
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
Similar mistake here:
char in[1000];
To hold a string of 1000 chars long, the array size should NOT be 1000.
char in[1000];
To hold a string of 1000 chars long, the array size should NOT be 1000.
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.