10894 - Save Hridoy

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

Moderator: Board moderators

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

10894 - Save Hridoy

Post by htl » Wed Aug 10, 2005 1:55 am

I wanna ask a small problem in the program. It's about the method in printing the string of length n. Let me assume that n<6.

Method 1

s[6]="*****";
s[n]='\0';
printf("%s",s);
s[n]='*';

Method 2

for(x=0;x<n;x++)
putchar('*');

The method 1 got WA and the method 2 got AC. But I wanna know why.

User avatar
Abednego
A great helper
Posts: 281
Joined: Tue Sep 10, 2002 5:14 am
Location: Mountain View, CA, USA
Contact:

Post by Abednego » Wed Aug 10, 2005 1:57 am

Are you sure that n<6? I don't think there can be a difference between the two programs unless n>=6.

And i hope you mean
char s[6] = "*****";
instead of
s[6] = "*****";
If only I had as much free time as I did in college...

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

Post by htl » Wed Aug 10, 2005 2:35 am

I know in this problem I have to declare a s[51]. And I set its value as a string of consecutive '*'s or '.'s. I just wanna know what's the difference between them.

User avatar
J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

Post by J&Jewel » Sat Aug 13, 2005 9:25 am

Hello dears I have got a problem about this problem...plz help me...

My out put is seems ok...but when vertically printing the output did not fixed in a line so I can't understend...my output...how can I make the output font small...so that it fixed in the range..?
I hate Wrong Answer!

User avatar
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Post by ibrahim » Sun Aug 14, 2005 8:27 pm

J&Jewel wrote:Hello dears I have got a problem about this problem...plz help me...

My out put is seems ok...but when vertically printing the output did not fixed in a line so I can't understend...my output...how can I make the output font small...so that it fixed in the range..?
You better take the output to file. :)
first make the input file. Let a.in
now run:

Code: Select all

a.exe <a.in >a.out 
You will get the out on a.out file.

Btw, you have to use command line on windows or terminal on linux. :)

User avatar
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Post by ibrahim » Sun Aug 14, 2005 8:35 pm

Input:

Code: Select all

2
-2
0
Output:

Code: Select all

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


**********
**********
**........
**........
**********
**********
........**
........**
**********
**********
..........
..........
..******..
..******..
**......**
**......**
**********
**********
**......**
**......**
**......**
**......**
..........
..........
**......**
**......**
**......**
**......**
**......**
**......**
..**..**..
..**..**..
....**....
....**....
..........
..........
**********
**********
**........
**........
******....
******....
**........
**........
**********
**********
..........
..........
..........
..........
..........
..........
**......**
**......**
**......**
**......**
**********
**********
**......**
**......**
**......**
**......**
..........
..........
**********
**********
**......**
**......**
**********
**********
**..**....
**..**....
**....****
**....****
..........
..........
**********
**********
....**....
....**....
....**....
....**....
....**....
....**....
**********
**********
..........
..........
******....
******....
**....**..
**....**..
**......**
**......**
**....**..
**....**..
******....
******....
..........
..........
**********
**********
**......**
**......**
**......**
**......**
**......**
**......**
**********
**********
..........
..........
**......**
**......**
..**..**..
..**..**..
....**....
....**....
....**....
....**....
....**....
....**....
Please some one check my output.

User avatar
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Post by ibrahim » Sun Aug 14, 2005 8:55 pm

Strange, i submit my previous code with a very small array size and got wrong answere.
And then make the array size more bigger and got RE (Strange :o )
And last submit with more bigger array and got accept (PE)


Then my question,
1. Why i got wrong answere insted of RE?
2. Why PE?
I have two new line in every cases execpt last.

User avatar
J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

Post by J&Jewel » Wed Aug 17, 2005 9:36 am

Thkx Ibrahim I have got AC I have an extra doted lines after Y...so silly mistake...And I can found it by print it to file....Thanks again...

I Think that u print the two new line after last case too....
I hate Wrong Answer!

User avatar
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Post by ibrahim » Thu Aug 18, 2005 5:35 am

J&Jewel wrote:Thkx Ibrahim I have got AC I have an extra doted lines after Y...so silly mistake...And I can found it by print it to file....Thanks again...

I Think that u print the two new line after last case too....
Great to hear that, my help works for you.

Btw, I skip the last two new line using flag. So i don't think that, i got PE for the new line. :(

User avatar
J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

Post by J&Jewel » Thu Aug 18, 2005 9:42 am

Ibrahim, U didn't understant.....
I say U got the P.E for do not print the new line after last case...

U should print two new line after last case too....then u can got the AC without P.E........Best of luck...
I hate Wrong Answer!

sunmoonstar_love
New poster
Posts: 13
Joined: Wed Aug 24, 2005 8:16 pm

10894 - Save Hridoy

Post by sunmoonstar_love » Thu Aug 25, 2005 2:21 pm

/*
I have submitted my code on many OJ, it can pass compiler,

but I got CE , why??

I'm not familiar with UVA's compiler
*/
#include<stdio.h>
void output2(char s[][6],int n, int r, int c)
{
char *tmp = new char[n*c+10];
int i,j,k,t;
for(i = 0; i < r; i++)
{
t = 0;
for(j = 0; j < c; j++)
{
for(k = 0; k < n; k++)
{
tmp[t++] = s[j];
}
}
tmp[t] = 0;
for(j = 0; j < n; j++)
printf("%s\n",tmp);
}
//printf("\n");
}
void output1(char s[][62],int n, int r, int c)
{
char *tmp = new char[n*c+10];
int i,j,k,t;
for(i = 0; i < r; i++)
{
t = 0;
for(j = 0; j < c; j++)
{
for(k = 0; k < n; k++)
{
tmp[t++] = s[j];
}
}
tmp[t] = 0;
for(j = 0; j < n; j++)
printf("%s\n",tmp);
}
printf("\n");
}
char s1[5][62] = {"*****..***..*...*.*****...*...*.*****.*****.***...*****.*...*",
"*.....*...*.*...*.*.......*...*.*...*...*...*..*..*...*..*.*.",
"*****.*****.*...*.***.....*****.*****...*...*...*.*...*...*..",
"....*.*...*..*.*..*.......*...*.*.*.....*...*..*..*...*...*..",
"*****.*...*...*...*****...*...*.*..**.*****.***...*****...*.."};
char s2[61][6] = {
"*****",
"*....",
"*****",
"....*",
"*****",
".....",
".***.",
"*...*",
"*****",
"*...*",
"*...*",
".....",
"*...*",
"*...*",
"*...*",
".*.*.",
"..*..",
".....",
"*****",
"*....",
"***..",
"*....",
"*****",
".....",
".....",
".....",
"*...*",
"*...*",
"*****",
"*...*",
"*...*",
".....",
"*****",
"*...*",
"*****",
"*.*..",
"*..**",
".....",
"*****",
"..*..",
"..*..",
"..*..",
"*****",
".....",
"***..",
"*..*.",
"*...*",
"*..*.",
"***..",
".....",
"*****",
"*...*",
"*...*",
"*...*",
"*****",
".....",
"*...*",
".*.*.",
"..*..",
"..*.."};

int main()
{
int n;
while(scanf("%d",&n) && n)
{
if(n < 0)
{
output2(s2, -n, 61, 5);
}
else
{
if(n > 0)
{
output1(s1, n, 5,61);
}
}
}
return 0;
}
I'm from China

User avatar
Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

Post by Cho » Thu Aug 25, 2005 3:33 pm

Did you submit it as C?
I code, therefore I am.

User avatar
Abednego
A great helper
Posts: 281
Joined: Tue Sep 10, 2002 5:14 am
Location: Mountain View, CA, USA
Contact:

Post by Abednego » Fri Aug 26, 2005 1:19 am

Check your email. The judge replies with the exact error message.
If only I had as much free time as I did in college...

worm3959
New poster
Posts: 4
Joined: Tue Nov 29, 2005 5:49 am
Contact:

Misunderstood

Post by worm3959 » Tue Nov 29, 2005 5:54 am

sunmoonstar_love wrote:/*
I am not sure if you understood what i meant, but i know that was not it.

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: Misunderstood

Post by Martin Macko » Sat Dec 10, 2005 4:08 pm

worm3959 wrote: I am not sure if you understood what i meant, but i know that was not it.
_________________
casinos no deposit online casinos
Sigh! another spammer :evil:

Post Reply

Return to “Volume 108 (10800-10899)”