Posted: Thu Jun 26, 2003 6:00 pm
can you show me how to parse the input? i dont know how to do it...
Code: Select all
IN:
a b f g
a b b f
v w x y z
v y x v z v w v
OUT:
a b f g
a b g f
a g b f
g a b f
w x z v y
w z x v y
x w z v y
x z w v y
z w x v y
z x w v y
Code: Select all
IN:
a b f g
a b b f
v w x y z
v y x v z v w v
f g b a
a b b f
a b c d
a b b c
a e i o u
a e
a b c d
a b a c a d
a b c d e
a b b c c d d e
a b c d e f g h i
a b b c c d d e e f f g g h h i
OUT:
a b f g
a b g f
a g b f
g a b f
w x z v y
w z x v y
x w z v y
x z w v y
z w x v y
z x w v y
a b f g
a b g f
a g b f
g a b f
a b c d
a b d c
a d b c
d a b c
a e i o u
a e i u o
a e o i u
a e o u i
a e u i o
a e u o i
a i e o u
a i e u o
a i o e u
a i o u e
a i u e o
a i u o e
a o e i u
a o e u i
a o i e u
a o i u e
a o u e i
a o u i e
a u e i o
a u e o i
a u i e o
a u i o e
a u o e i
a u o i e
i a e o u
i a e u o
i a o e u
i a o u e
i a u e o
i a u o e
i o a e u
i o a u e
i o u a e
i u a e o
i u a o e
i u o a e
o a e i u
o a e u i
o a i e u
o a i u e
o a u e i
o a u i e
o i a e u
o i a u e
o i u a e
o u a e i
o u a i e
o u i a e
u a e i o
u a e o i
u a i e o
u a i o e
u a o e i
u a o i e
u i a e o
u i a o e
u i o a e
u o a e i
u o a i e
u o i a e
a b c d
a b d c
a c b d
a c d b
a d b c
a d c b
a b c d e
a b c d e f g h i
There's no blank line after the last line.. or at least mine didn't give one..Output for different constraint specifications is separated by a blank line
Code: Select all
#ifndef ONLINE_JUDGE
#include <iostream>
#include <io.h>
using namespace std;
#else
#include <iostream.h>
#include <stdio.h>
#endif
char* end, n;
char b[256];
char u[26];
char l[26];
char e[26];
char t[26];
char a[26][26];
char d[26][26];
void print(char i, char* p)
{
*++p = l[u[i] = i];
if (p < end){
for (char *k, j = 0; j < n; ++j)
if (u[j] == '-')//not used
if (a[i][j] == '-' ||//belong to this chain
d[i][j] != '-') //and next in chain
{
for (k = p; k >= b; --k)
if (a[j][e[*k-'a']] != '-') break;
if (k < b) print(j, p);
}
}else printf(b);
u[i] = '-';
}
void main()
{
#ifndef ONLINE_JUDGE
close(0);
open("input.txt", 0);
#endif
while (1)
{
cin.getline(b, sizeof(b));
if (cin.peek() < 0) break;
char *p, c, c2, i, j; n = 0;
memset(u, '-', sizeof(u));
memset(l, '-', sizeof(l));
memset(e, '-', sizeof(e));
memset(a, '-', sizeof(a));
memset(d, '-', sizeof(d));
for (p = b; *p; p++)
if ('a' <= *p && *p <= 'z')
e[*p-'a'] = *p;
for (c = 0; c < 26; c++)
if (e[c] != '-')
l[e[c] = n++] = c+'a',
t[e[c]] = c + 'a';
cin.getline(b, sizeof(b));
for (p = b; *p; p++)
{
if (*p < 'a') continue;
if (*p > 'z') continue;
char* p2 = p;
for (++p; *p; ++p)
{
if (*p < 'a') continue;
if (*p > 'z') continue;
break;
}
a[c2 = e[*p2-'a']][c = e[*p-'a']] = *p;
d[c2][c] = *p;
t[c] = '-';
for (i = 0; i < n; i++)
{
if (a[i][c2] != '-')
for (j = 0; j < n; ++j)
if (a[c2][j] != '-')
a[i][j] = *p;
if (a[i][c] != '-')
for (j = 0; j < n; ++j)
if (a[c][j] != '-')
a[i][j] = l[j];
if (a[i][c2] != '-' && a[i][c] != '-')
d[i][c] = '-';
}
}
*((end = b + n - 1)+1) = '\n', *(end+2) = '\0';
for (i = 0; i < n; ++i)
if (t[i] != '-')//root of chain
print(i, b-1);
printf("\n");
}
}
Well, my g++ says the following (unimportant messages omitted):OZone wrote:Hi! I've compiled following code in MSVC7.1 and even in Borland C. Everything is fine. So why do it gets compile errors in online judge?
I recieved by e-mail tough list of errors but they did not give me any clue to understang the problems. What is the character 0232, and why my declared variables suddenly became undeclared? The code is:Sincerly yours, OZone!Code: Select all
... deleted, see parent post...
Code: Select all
a.cc:3:16: io.h: No such file or directory
a.cc: At global scope:
a.cc:37: error: `main' must return `int'
a.cc:37: error: return type for `main' changed to `int'
a.cc: In function `int main(...)':
a.cc:40: error: `open' undeclared (first use this function)
I do not understand what do they mean. It seems more worse than I even thought about.03526697_24.c: In function `void print(char, char *)':
03526697_24.c:22: parse error before character 0232
03526697_24.c:24: `j' undeclared (first use this function)
03526697_24.c:24: (Each undeclared identifier is reported only once
03526697_24.c:24: for each function it appears in.)
03526697_24.c:24: parse error before `)'
03526697_24.c:29: `k' undeclared (first use this function)
03526697_24.c:29: parse error before `)'
03526697_24.c: In function `int main(...)':
03526697_24.c:43: parse error before character 0232
03526697_24.c:48: parse error before character 0232
03526697_24.c:53: `p' undeclared (first use this function)
03526697_24.c:53: parse error before `)'
03526697_24.c:56: `c' undeclared (first use this function)
03526697_24.c:56: parse error before `)'
03526697_24.c:61: parse error before `)'
03526697_24.c:66: parse error before `)'
03526697_24.c: At top level:
03526697_24.c:75: parse error before `;'
03526697_24.c:75: syntax error before `++'
03526697_24.c:78: parse error before `;'
03526697_24.c:78: syntax error before `++'
03526697_24.c:82: parse error before `;'
03526697_24.c:82: syntax error before `++'
03526697_24.c:90: parse error before `;'