I'll get back to it once the queue clears, and hopefully that was the only thing wrong. Thanks for taking a look though!
490 - Rotating Sentences
Moderator: Board moderators
Re: 490 - Rotating Sentence
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!
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
Thanks for the update. Fantastic work! Glad your debugging went well.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
Let us know how it goes.I'll get back to it once the queue clears, and hopefully that was the only thing wrong.
Re: 490 - Rotating Sentence
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
Glad you figured it out. Well done!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.
In regards to the zero character. That's represented by
Code: Select all
'0'Code: Select all
'\0'Re: 490 - Rotating Sentence
Right, I meant ASCII null. I guess calling it "character zero" is confusing. Then again this is also null: ? 
-
battirunner
- New poster
- Posts: 14
- Joined: Fri Aug 15, 2014 3:48 pm
Re: 490 - Rotating Sentences
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;
}
#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
Code: Select all
Use code tagsCode: 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
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
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
Yes, you are right. Just add one line
Input
Acc. Output
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
Don't forget to remove all your codes after getting accepted. 
Code: Select all
while(j--)
{
if (a[j][k] == '\0') a[j][k] = ' ';
printf("%c",a[j][k]);
}Code: Select all
a
bb
ccc
dddd
eeeee
ffff
gggCode: Select all
gfedcba
gfedcb
gfedc
fed
eStrings "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++;
}A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
UVA 490-Rotating sentences WA
Please help,
what's wrong with my code, getting WA...
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.
Re: UVA 490-Rotating sentences WA
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
It will be good if you remove all your codes after getting accepted. 
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));
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 490 - Rotating Sentences
I have done that all you say. But still WA. I think problem with stopping input. please, see again.
Re: 490 - Rotating Sentences
NAbdulla, i checked both ways i posted and now i got accepted with your code fourth time. 
Problems with copy/paste?
Submit code from your post above, not from your pc.
Problems with copy/paste?
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
Re: 490 - Rotating Sentences
Thanks a lot but I can't.

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