403 - Postscript

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Tomislav Novak
New poster
Posts: 44
Joined: Fri Feb 20, 2004 5:52 pm

403 - PostScript

Post by Tomislav Novak »

Hi.

I'm trying to solve problem 403 but keep getting wrong answer.
[c]
#include <stdio.h>

char c5[26][30] =
{
".***..*...*.*****.*...*.*...*.",
"****..*...*.****..*...*.****..",
".****.*...*.*.....*......****.",
"****..*...*.*...*.*...*.****..",
"*****.*.....***...*.....*****.",
"*****.*.....***...*.....*.....",

".****.*.....*..**.*...*..***..",
"*...*.*...*.*****.*...*.*...*.",
"*****...*.....*.....*...*****.",
"..***....*.....*..*..*...**...",
"*...*.*..*..***...*..*..*...*.",
"*.....*.....*.....*.....*****.",
"*...*.**.**.*.*.*.*...*.*...*.",
"*...*.**..*.*.*.*.*..**.*...*.",
".***..*...*.*...*.*...*..***..",
"****..*...*.****..*.....*.....",
".***..*...*.*...*.*..**..****.",
"****..*...*.****..*..*..*...*.",
".****.*......***......*.****..",
"*****.*.*.*...*.....*....***..",
"*...*.*...*.*...*.*...*..***..",
"*...*.*...*..*.*...*.*....*...",
"*...*.*...*.*.*.*.**.**.*...*.",
"*...*..*.*....*....*.*..*...*.",
"*...*..*.*....*.....*.....*...",
"*****....*....*....*....*****."
};

char page[60][60];

void blank()
{
int i, j;

for (i = 0; i < 60; i++)
for (j = 0; j < 60; j++)
page[j] = '.';
}

void dump_page()
{
int i, j;

/* printf(" ");
for (i = 1; i <= 60; i++)
printf("%d", i % 10);

printf("\n");*/

for (i = 0; i < 60; i++)
{
/* printf("%2d: ", i + 1); /* DEBUG: print the line number */
for (j = 0; j < 60; j++) fprintf(stderr, "%c", page[j]);
fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
for (i = 0; i < 60; i++) fprintf(stderr, "-");
fprintf(stderr, "\n\n");
}

void print(int row, int column, int size, int align, char *text)
{
int left, right, letter, i, j, k;
char c;

/* calculate the positions */
if (!align || align == 1)
{
left = column - 1;
if (size == 1) right = left + strlen(text) - 1;
else right = left + strlen(text) * 6 - 1;
}
else if (align == 2)
{
right = column - 1;
if (size == 1) left = right - strlen(text) + 1;
else left = right - strlen(text) * 6 + 1;
}
else if (align == 3)
{
if (size == 1)
{
left = 29 - strlen(text) / 2 + strlen(text) % 2;
right = left + strlen(text) - 1;
}
else
{
left = 30 - strlen(text) * 3;
right = left + strlen(text) * 6 - 1;
}
}

/* the actual printing */
if (size == 1)
{
for (i = left; i <= right; i++)
{
if (i < 0 || i > 59) continue;

if (text[abs(i - left)] != ' ')
page[row - 1] = text[abs(i - left)];
}
}
else
{
for (k = 0; k < 5; k++)
{
for (i = left; i <= right; i++)
{
if (i < 0 || i > 59) continue;

letter = abs(i - left) / 6;
if (toupper(text[letter]) - 'A' < 26 &&
toupper(text[letter]) - 'A' >= 0)
c = c5[toupper(text[letter]) - 'A'][k * 6 + abs(i - left) % 6];
else
c = '.';

if (row + k - 1 < 60)
if (c != '.')
page[row + k - 1] = c;
}
}
}
}

int main()
{
char cmd[5], font[3], text[1024], tmp[1024];
int row, column, fsize, i, j, align;

blank();

while (scanf("%s", cmd) == 1 && strcmp(cmd, ".EOP"))
{
row = column = 1;

scanf("%s", font); scanf("%d", &row);

align = 0;
if (!strcmp(cmd, ".P")) scanf("%d", &column);
else if (!strcmp(cmd, ".L"))
{
column = 1;
align = 1; /* left alignment */
}
else if (!strcmp(cmd, ".R"))
{
column = 60;
align = 2; /* right alignment */
}
else if (!strcmp(cmd, ".C")) align = 3;

fgets(tmp, 1024, stdin); tmp[strlen(tmp) - 1] = '\0';
/* get rid of the delimiters */
strcpy(text, tmp + 2);
for (i = strlen(text) - 1; i >= 0; i--)
if (text == '|')
{
text = '\0';
break;
}

if (!strcmp(font, "C5")) fsize = 5;
else fsize = 1;

print(row, column, fsize, align, text);

}

dump_page();

return 0;
}
[/c]

manbed
New poster
Posts: 1
Joined: Sun Feb 29, 2004 5:24 pm

Post by manbed »

I have the same problem than you. I have a code similar your code and the result always is wrong answer.
I see your code and I don't know why you use toupper, because I think that if the text have a 'b' the program have not print this character.

Well, if you can pass the problem, answer in this post and say why your old program didn't pass the problem.

Thanks and luck whit the problem!

A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 »

Why you two get WA ? Answer is :
First read this:
http://online-judge.uva.es/board/viewto ... hlight=403
And Second :
your program should run untill the end of file. That is input could be like this:

Code: Select all

.C C5 3 |ACM| 
.P C1 33 11 |LINE THAT OVERWRITES THROUGH CENTERED| 
.L C1 40 |SMALL FONT LINE IS LEFT JUSTIFIED ON ROW FORTY| 
.R C5 50 |RIGHT| 
.P C5 57 10 |BOTTOM AND RIGHT TRUNCATION| 
.EOP
.C C5 3 |ACM| 
.C C1 10 |SOUTH CENTRAL REGION PROBLEM FOUR SAMPLE OUTPUT| 
.C C5 20 |OVERFLOW CENTERED LARGE FONT| 
.C C5 30 |CENTERED| 
.P C5 57 10 |BOTTOM AND RIGHT TRUNCATION| 
.EOP
So you have to print two pages , but Tomislav Novak prog print ony one and end!

mars kaseijin
New poster
Posts: 22
Joined: Mon Sep 19, 2005 4:58 am
Contact:

403 Postscript - Access Denied

Post by mars kaseijin »

Greetings acm,
i have submitted my code through Sub-O-Matic 6.0
it results in "Access Denied"
Have anyone here experienced this? :roll:

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

You get "Access Denied" when you dont post your solution from the address you speciefied in your registration form. There is an option in your settings that says you will always submit from the specified host, i.e. the email address you have given here when registering in the uva.es. Change that option to 'any host'. That's all.

mars kaseijin
New poster
Posts: 22
Joined: Mon Sep 19, 2005 4:58 am
Contact:

Post by mars kaseijin »

thank you very much, Kamal :P

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

403- need some help

Post by emotional blind »

what should be the output of this input set

Code: Select all

.C C5 3 |ACM| 
.C C1 10 |SOUTH CENTRAL REGION PROBLEM FOUR SAMPLE OUTPUT|
.C C5 20 |OVERFLOW CENTERED LARGE FONT| 
.C C5 20 |ACM| 
.P C1 33 11 |LINE THAT OVERWRITES THROUGH CENTERED|
.C C5 30 |CENTERED|   
.R C1 40 |SMALL FONT LINE IS LEFT JUSTIFIED ON ROW FORTY SMALL FONT LINE IS LEFT JUSTIFIED ON ROW FORTY| 
.C C1 40 |ARIF  |
.C C1 41 |ARI|
.R C5 50 |RIGHT AND WORK| 
.P C5 56 10 |BOTTOM AND RIGHT TRUNCATION| 
.EOP


.EOP
my program generates this output

Code: Select all

............................................................
............................................................
......................***...****.*...*......................
.....................*...*.*...*.**.**......................
.....................*****.*.....*.*.*......................
.....................*...*.*.....*...*......................
.....................*...*..****.*...*......................
............................................................
............................................................
.......SOUTH.CENTRAL.REGION.PROBLEM.FOUR.SAMPLE.OUTPUT......
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
.****.*****.*...*.****************..*****.****........*.....
*...*.*.....**..*.*.***.**.*..**.**.**....*...*.......*.....
*.....***...*.*.*...********..****.****...*...*.......*.....
*.....*.....*..**...**..**.*..*..*..**....*...*.......*.....
.****.*****.*...*..***..********.**.*****.****........*****.
............................................................
............................................................
............................................................
............................................................
............................................................
.......****.*****.*...*.*****.*****.****..*****.****........
......*...*.*.....**..*.*.*.*.*.....*...*.*.....*...*.......
......*.....***...*.*.*...*...***...****..***...*...*.......
......*...LI*E.THA*.O**RWR*TES*THROU*H.*EN*ERED.*...*.......
.......****.*****.*...*..***..*****.*...*.*****.****........
............................................................
............................................................
............................................................
............................................................
............................................................
.ON.ROW.FORTY.SMALL.FONT.LIARIFS.LEFT.JUSTIFIED.ON.ROW.FORTY
.............................ARI............................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
*****........***..*...*.****........*...*..***..****..*...*.
*.*.*.......*...*.**..*.*...*.......*...*.*...*.*...*.*..*..
..*.........*****.*.*.*.*...*.......*.*.*.*...*.****..***...
..*.........*...*.*..**.*...*.......**.**.*...*.*..*..*..*..
.***........*...*.*...*.****........*...*..***..*...*.*...*.
............................................................
.........****...***..*****.*****..***..*...*........***..*..
.........*...*.*...*.*.*.*.*.*.*.*...*.**.**.......*...*.**.
.........****..*...*...*.....*...*...*.*.*.*.......*****.*.*
.........*...*.*...*...*.....*...*...*.*...*.......*...*.*..
.........****...***...***...***...***..*...*.......*...*.*..

------------------------------------------------------------

............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................

------------------------------------------------------------

is this correct
i get lot of WA in this problem

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

403 - Postscript

Post by emotional blind »

what should be the output of this input set

Code: Select all

.C C5 3 |ACM| 
.C C1 10 |SOUTH CENTRAL REGION PROBLEM FOUR SAMPLE OUTPUT|
.C C5 20 |OVERFLOW CENTERED LARGE FONT| 
.C C5 20 |ACM| 
.P C1 33 11 |LINE THAT OVERWRITES THROUGH CENTERED|
.C C5 30 |CENTERED|   
.R C1 40 |SMALL FONT LINE IS LEFT JUSTIFIED ON ROW FORTY SMALL FONT LINE IS LEFT JUSTIFIED ON ROW FORTY| 
.C C1 40 |ARIF  |
.C C1 41 |ARI|
.R C5 50 |RIGHT AND WORK| 
.P C5 56 10 |BOTTOM AND RIGHT TRUNCATION| 
.EOP


.EOP
my program generates this output

Code: Select all

............................................................
............................................................
......................***...****.*...*......................
.....................*...*.*...*.**.**......................
.....................*****.*.....*.*.*......................
.....................*...*.*.....*...*......................
.....................*...*..****.*...*......................
............................................................
............................................................
.......SOUTH.CENTRAL.REGION.PROBLEM.FOUR.SAMPLE.OUTPUT......
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
.****.*****.*...*.****************..*****.****........*.....
*...*.*.....**..*.*.***.**.*..**.**.**....*...*.......*.....
*.....***...*.*.*...********..****.****...*...*.......*.....
*.....*.....*..**...**..**.*..*..*..**....*...*.......*.....
.****.*****.*...*..***..********.**.*****.****........*****.
............................................................
............................................................
............................................................
............................................................
............................................................
.......****.*****.*...*.*****.*****.****..*****.****........
......*...*.*.....**..*.*.*.*.*.....*...*.*.....*...*.......
......*.....***...*.*.*...*...***...****..***...*...*.......
......*...LI*E.THA*.O**RWR*TES*THROU*H.*EN*ERED.*...*.......
.......****.*****.*...*..***..*****.*...*.*****.****........
............................................................
............................................................
............................................................
............................................................
............................................................
.ON.ROW.FORTY.SMALL.FONT.LIARIFS.LEFT.JUSTIFIED.ON.ROW.FORTY
.............................ARI............................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
*****........***..*...*.****........*...*..***..****..*...*.
*.*.*.......*...*.**..*.*...*.......*...*.*...*.*...*.*..*..
..*.........*****.*.*.*.*...*.......*.*.*.*...*.****..***...
..*.........*...*.*..**.*...*.......**.**.*...*.*..*..*..*..
.***........*...*.*...*.****........*...*..***..*...*.*...*.
............................................................
.........****...***..*****.*****..***..*...*........***..*..
.........*...*.*...*.*.*.*.*.*.*.*...*.**.**.......*...*.**.
.........****..*...*...*.....*...*...*.*.*.*.......*****.*.*
.........*...*.*...*...*.....*...*...*.*...*.......*...*.*..
.........****...***...***...***...***..*...*.......*...*.*..

------------------------------------------------------------

............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................

------------------------------------------------------------

is this correct
i get lot of WA in this problem

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

Your I/O is not valid. From the problem description:
Argument 4 is a string of up to 60 valid characters (upper case letters or space if font is C5, or any printable character if font is C1) delimited by the `|'.
The string(argument 4) for this:
.R C1 40 |SMALL FONT LINE IS LEFT JUSTIFIED ON ROW FORTY SMALL FONT LINE IS LEFT JUSTIFIED ON ROW FORTY|
is longer than 60 characters.

Anyway, changing the string to within 60 characters, my AC code gives a different output - the only difference is it does not print the string "LINE THAT OVERWRITES THROUGH CENTERED" at all.

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

so what is your output shows
send to the forum plz
if you or anyone can send some more critical input

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

Give the following input:

Code: Select all

.C C5 3 |ACM|
.C C1 10 |SOUTH CENTRAL REGION PROBLEM FOUR SAMPLE OUTPUT|
.C C5 20 |OVERFLOW CENTERED LARGE FONT|
.C C5 20 |ACM|
.P C1 33 11 |LINE THAT OVERWRITES THROUGH CENTERED|
.C C5 30 |CENTERED|
.R C1 40 |SMALL FONT LINE IS LEFT JUSTIFIED ON ROW FORTY|
.C C1 40 |ARIF  |
.C C1 41 |ARI|
.R C5 50 |RIGHT AND WORK|
.P C5 56 10 |BOTTOM AND RIGHT TRUNCATION|
.EOP
.EOP
My AC program's output is:

Code: Select all

............................................................
............................................................
......................***...****.*...*......................
.....................*...*.*...*.**.**......................
.....................*****.*.....*.*.*......................
.....................*...*.*.....*...*......................
.....................*...*..****.*...*......................
............................................................
............................................................
.......SOUTH.CENTRAL.REGION.PROBLEM.FOUR.SAMPLE.OUTPUT......
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
.****.*****.*...*.***.***...****.*...*.**.****........*.....
*...*.*.....**..*.*.**...*.*...*.**.**....*...*.......*.....
*.....***...*.*.*...******.*.....*.*.*....*...*.......*.....
*.....*.....*..**...**...*.*.....*...*....*...*.......*.....
.****.*****.*...*..***...*..****.*...*.**.****........*****.
............................................................
............................................................
............................................................
............................................................
............................................................
.......****.*****.*...*.*****.*****.****..*****.****........
......*...*.*.....**..*.*.*.*.*.....*...*.*.....*...*.......
......*.....***...*.*.*...*...***...****..***...*...*.......
......*.....*.....*..**...*...*.....*..*..*.....*...*.......
.......****.*****.*...*..***..*****.*...*.*****.****........
............................................................
............................................................
............................................................
............................................................
............................................................
..............SMALL.FONT.LIARIFS.LEFT.JUSTIFIED.ON.ROW.FORTY
.............................ARI............................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
*****........***..*...*.****........*...*..***..****..*...*.
*.*.*.......*...*.**..*.*...*.......*...*.*...*.*...*.*..*..
..*.........*****.*.*.*.*...*.......*.*.*.*...*.****..***...
..*.........*...*.*..**.*...*.......**.**.*...*.*..*..*..*..
.***........*...*.*...*.****........*...*..***..*...*.*...*.
............................................................
.........****...***..*****.*****..***..*...*........***..*..
.........*...*.*...*.*.*.*.*.*.*.*...*.**.**.......*...*.**.
.........****..*...*...*.....*...*...*.*.*.*.......*****.*.*
.........*...*.*...*...*.....*...*...*.*...*.......*...*.*..
.........****...***...***...***...***..*...*.......*...*.*..

------------------------------------------------------------

............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................ 
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................

------------------------------------------------------------

There are no blank lines in the input and my AC code will crash if there are blank lines in the input.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Your outputs are correct.
Ami ekhono shopno dekhi...
HomePage

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

i got wa again and again
what can i do?
can i send you my code in PM

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

i got wa... why?
my outputs are now same to you
how can you help me?

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Check the input/output set. If your code passes then you can send me your code.

Input:

Code: Select all

.C C5 10 |THE QUICK| 
.C C5 20 |BROWN| 
.C C5 30 |FOX JUMPS| 
.P C5 40 11 |OVER THE| 
.C C5 50 |LAZY  DOG| 
.P C5 60 45|TIME| 
.R C5 1 |JAN   SAYS|   
.EOP
Output:

Code: Select all

..***..***..*...*....................****..***..*...*..****.
...*..*...*.**..*...................*.....*...*..*.*..*.....
...*..*****.*.*.*....................***..*****...*....***..
*..*..*...*.*..**.......................*.*...*...*.......*.
.**...*...*.*...*...................****..*...*...*...****..
............................................................
............................................................
............................................................
............................................................
...*****.*...*.*****........***..*...*.*****..****.*...*....
...*.*.*.*...*.*...........*...*.*...*...*...*...*.*..*.....
.....*...*****.***.........*...*.*...*...*...*.....***......
.....*...*...*.*...........*..**.*...*...*...*.....*..*.....
....***..*...*.*****........****..***..*****..****.*...*....
............................................................
............................................................
............................................................
............................................................
............................................................
...............****..****...***..*...*.*...*................
...............*...*.*...*.*...*.*...*.**..*................
...............****..****..*...*.*.*.*.*.*.*................
...............*...*.*..*..*...*.**.**.*..**................
...............****..*...*..***..*...*.*...*................
............................................................
............................................................
............................................................
............................................................
............................................................
...*****..***..*...*.........***.*...*.*...*.****...****....
...*.....*...*..*.*...........*..*...*.**.**.*...*.*........
...***...*...*...*............*..*...*.*.*.*.****...***.....
...*.....*...*..*.*........*..*..*...*.*...*.*.........*....
...*......***..*...*........**....***..*...*.*.....****.....
............................................................
............................................................
............................................................
............................................................
............................................................
...........***..*...*.*****.****........*****.*...*.*****...
..........*...*.*...*.*.....*...*.......*.*.*.*...*.*.......
..........*...*..*.*..***...****..........*...*****.***.....
..........*...*..*.*..*.....*..*..........*...*...*.*.......
...........***....*...*****.*...*........***..*...*.*****...
............................................................
............................................................
............................................................
............................................................
............................................................
...*......***..*****.*...*.............****...***...****....
...*.....*...*....*...*.*..............*...*.*...*.*........
...*.....*****...*.....*...............*...*.*...*.*..**....
...*.....*...*..*......*...............*...*.*...*.*...*....
...*****.*...*.*****...*...............****...***...***.....
............................................................
............................................................
............................................................
............................................................
............................................................
............................................*****.*****.*...

------------------------------------------------------------
Hope it works.
Ami ekhono shopno dekhi...
HomePage

Post Reply

Return to “Volume 4 (400-499)”