Page 14 of 15

Re: 490 - Rotating Sentence

Posted: Fri May 09, 2014 10:35 am
by johncip
I had a typo when checking for character zero, meant '\0' but write '0'. And to top it off, I think that check was unnecessary (included it before I had hard grid bounds), so it wasn't doing anything but introducing the bug :(

I'll get back to it once the queue clears, and hopefully that was the only thing wrong. Thanks for taking a look though!

Re: 490 - Rotating Sentence

Posted: Fri May 09, 2014 10:43 am
by uDebug
johncip wrote:I had a typo when checking for character zero, meant '\0' but write '0'. And to top it off, I think that check was unnecessary (included it before I had hard grid bounds), so it wasn't doing anything but introducing the bug :(
Thanks for the update. Fantastic work! Glad your debugging went well.
I'll get back to it once the queue clears, and hopefully that was the only thing wrong.
Let us know how it goes.

Re: 490 - Rotating Sentence

Posted: Fri May 09, 2014 11:48 am
by johncip
Got it now, thanks. I suppose now I'll be more careful about character zero. I like to use '\0' since it stands out more as a special value in the code, if that makes any sense. But it makes that sort of typo possible, so maybe it's not a great idea.

Re: 490 - Rotating Sentence

Posted: Sat May 10, 2014 7:04 am
by uDebug
johncip wrote:Got it now, thanks. I suppose now I'll be more careful about character zero. I like to use '\0' since it stands out more as a special value in the code, if that makes any sense. But it makes that sort of typo possible, so maybe it's not a great idea.
Glad you figured it out. Well done!

In regards to the zero character. That's represented by

Code: Select all

'0'
What you wrote above is the null character

Code: Select all

'\0'

Re: 490 - Rotating Sentence

Posted: Sun May 11, 2014 2:22 am
by johncip
Right, I meant ASCII null. I guess calling it "character zero" is confusing. Then again this is also null: ? :D

Re: 490 - Rotating Sentences

Posted: Wed Sep 03, 2014 6:32 pm
by battirunner
why getting WA, checked with critical input in uDebug, please help, thanks in advance


#include<stdio.h>
#include<string.h>
int main()
{
char a[125][125];
int i=0,j,k=0,x=0,maxi=0;
//freopen("in.txt","r",stdin);
for(i = 0; i < 125;i++)
{
for(j = 0; j < 125;j++)
a[j] = ' ';
}
i=0;
while(gets(a))
{
x=strlen(a);
if(x>maxi)
maxi=x;
i++;
}
while(k<maxi)
{
j=i;
while(j--)
{
printf("%c",a[j][k]);
}
k++;
printf("\n");
}
return 0;
}

Re: 490 - Rotating Sentences

Posted: Wed Sep 03, 2014 7:10 pm
by lighted

Code: Select all

Use code tags
You are printing extra spaces. Your Output

Code: Select all

"R
Ie
 n
te
h <-extra space here
iD
ne
kc
,a
 r
tt
he
es
r <-extra space here
eo
fn
oc
re
e <-extra space here
 s
Ia
 i
ad
m,
. <-extra space here
" <-extra space here 
I think it will be good if you remove all your codes after getting accepted. 8)

Re: 490 - Rotating Sentences

Posted: Tue Sep 09, 2014 7:15 am
by battirunner
how could it be extra space, i have checked it in uDebug, it provide the same answer, also with the critical input of uDebug, that was same too. It is said to print the sentence same to same including spaces just by rotate it. So i can't figure out the problem

Re: 490 - Rotating Sentences

Posted: Tue Sep 09, 2014 12:47 pm
by lighted
Yes, you are right. Just add one line

Code: Select all

while(j--)
{
  if (a[j][k] == '\0') a[j][k] = ' ';

  printf("%c",a[j][k]);
}
Input

Code: Select all

a
bb
ccc
dddd
eeeee
ffff
ggg
Acc. Output

Code: Select all

gfedcba
gfedcb
gfedc
 fed
  e
For this input your program is printing '\0' character at the beginning of 4th, 5th. If you run your code on http://www.ideone.com it may not be visible, but it can be seen on http://www.compileonline.com

Strings "ffff" and "ggg" end with '\0', not space. So you could also add one line

Code: Select all

while(gets(a[i]))
{
  x=strlen(a[i]);

  a[i][x] = ' ';

  if(x>maxi) maxi=x;
  
  i++;
}
Don't forget to remove all your codes after getting accepted. 8)

UVA 490-Rotating sentences WA

Posted: Tue Sep 16, 2014 12:48 pm
by NAbdulla
Please help,
what's wrong with my code, getting WA...

Code: Select all

removed

Re: UVA 490-Rotating sentences WA

Posted: Tue Sep 16, 2014 5:22 pm
by lighted
Post in existing threads. Don't open new thread. Use search box by problem number (490).

Make your array s[105][105] global. When it is local there is no guarantee that initiallly it is filled with '\0'.

Or you can initialize it yourself

Code: Select all

char s[105][105];
    
memset(s, 0, sizeof(s));
It will be good if you remove all your codes after getting accepted. 8)

Re: 490 - Rotating Sentences

Posted: Thu Sep 18, 2014 8:53 am
by NAbdulla
I have done that all you say. But still WA. I think problem with stopping input. please, see again.

Re: 490 - Rotating Sentences

Posted: Thu Sep 18, 2014 3:17 pm
by lighted
NAbdulla, i checked both ways i posted and now i got accepted with your code fourth time. :)
Problems with copy/paste? :D
Submit code from your post above, not from your pc.

Re: 490 - Rotating Sentences

Posted: Thu Sep 18, 2014 7:48 pm
by NAbdulla
Thanks a lot but I can't. :( :roll:

Re: 490 - Rotating Sentences

Posted: Fri Sep 19, 2014 10:53 am
by lighted
I see that you've done it. :D