490 - Rotating Sentences

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

johncip
New poster
Posts: 4
Joined: Fri May 09, 2014 8:43 am

Re: 490 - Rotating Sentence

Post 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!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 490 - Rotating Sentence

Post 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.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

johncip
New poster
Posts: 4
Joined: Fri May 09, 2014 8:43 am

Re: 490 - Rotating Sentence

Post 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.

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 490 - Rotating Sentence

Post 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'
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

johncip
New poster
Posts: 4
Joined: Fri May 09, 2014 8:43 am

Re: 490 - Rotating Sentence

Post by johncip »

Right, I meant ASCII null. I guess calling it "character zero" is confusing. Then again this is also null: ? :D

battirunner
New poster
Posts: 14
Joined: Fri Aug 15, 2014 3:48 pm

Re: 490 - Rotating Sentences

Post 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;
}

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 490 - Rotating Sentences

Post 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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

battirunner
New poster
Posts: 14
Joined: Fri Aug 15, 2014 3:48 pm

Re: 490 - Rotating Sentences

Post 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

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 490 - Rotating Sentences

Post 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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

UVA 490-Rotating sentences WA

Post by NAbdulla »

Please help,
what's wrong with my code, getting WA...

Code: Select all

removed
Last edited by NAbdulla on Thu Sep 18, 2014 7:53 pm, edited 1 time in total.

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: UVA 490-Rotating sentences WA

Post 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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

Re: 490 - Rotating Sentences

Post by NAbdulla »

I have done that all you say. But still WA. I think problem with stopping input. please, see again.

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 490 - Rotating Sentences

Post 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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

Re: 490 - Rotating Sentences

Post by NAbdulla »

Thanks a lot but I can't. :( :roll:

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 490 - Rotating Sentences

Post by lighted »

I see that you've done it. :D
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 4 (400-499)”