490 - Rotating Sentences
Moderator: Board moderators
Re: 490 - Rotating Sentences
Thanks for your reply . . . . . . .
-
- New poster
- Posts: 6
- Joined: Sun Jul 21, 2013 1:36 pm
490 - Rotating Sentence
.
Last edited by marufsharif on Mon Jul 29, 2013 12:30 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 490 - Rotating Sentence
For the sample input, there should be a space at the end of the last two lines of the output.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 6
- Joined: Sun Jul 21, 2013 1:36 pm
Re: 490 - Rotating Sentence
thanks
Last edited by marufsharif on Mon Jul 29, 2013 12:30 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 490 - Rotating Sentence
Print a newline at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 6
- Joined: Sun Jul 21, 2013 1:36 pm
Re: 490 - Rotating Sentence
Post Remove, After Accept
Last edited by marufsharif on Mon Jul 29, 2013 12:28 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 490 - Rotating Sentence
Try input:
Code: Select all
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Check input and AC output for thousands of problems on uDebug!
Re: 490 - Rotating Sentence
PE !
Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
int i=0,j,temp,max_len=0;
char string[101][101];
while(gets(string[i]))
{
if(strlen(string[i])>max_len)
max_len=strlen(string[i]);
i++;
}
temp=i;
j=0;
while(j<max_len)
{
i=temp;
while(i>=0)
{
if(j>=strlen(string[i]))
printf(" ");
else
printf("%c",string[i][j]);
i--;
}
printf("\n");
j++;
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 490 - Rotating Sentence
For the sample input, don't print a space at the beginning of every line.
Check input and AC output for thousands of problems on uDebug!
Re: 490 - Rotating Sentence
As brianfry713's mentioned, unfortunately, the sample output's faulty. (On the input, Decartes's mispelled - it should be "Descartes". Though this isn't critical to solving the problem.)
Input:
AC Output:
Input:
Code: Select all
Rene Decartes once said,
"I think, therefore I am."
Code: Select all
"R
Ie
n
te
h
iD
ne
kc
,a
r
tt
he
es
r
eo
fn
oc
re
e
s
Ia
i
ad
m,
.
"
Last edited by uDebug on Sat Feb 22, 2014 1:39 pm, edited 2 times in total.
Re: 490 - Rotating Sentence
Here's some input / output to make things clearer in regards to the spaces.
Input:
AC Output:
Input:
Code: Select all
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque a sem euismod magna consequat
sodales. In mollis fringilla volutpat. Ut ut condimentum nulla, ac tincidunt lectus. Mauris a
rhoncus enim. Vivamus tincidunt arcu mi, sit amet feugiat turpis suscipit vel. Nulla convallis
Quisque id lacus at nulla laoreet malesuada vitae aliquam tellus. Pellentesque vehicula laoreet
feugiat nulla, vel tristique augue egestas vel. Curabitur pretium mauris cursus dolor tristique
lobortis. Morbi mollis bibendum ante eget pharetra. Donec eu lorem leo. Vestibulum ante ipsum
primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam hendrerit arcu a porta
venenatis. Cras ornare ipsum ac dolor congue auctor. Phasellus vitae placerat sem. Ut et lorem
quam. Donec suscipit turpis a eros ullamcorper, vitae lobortis eros sodales. Cras lorem odio,
sollicitudin a rhoncus in, cursus vitae lorem. In feugiat posuere fermentum. Nulla lacus metus,
sagittis et lacus nec, accumsan fringilla libero. Nam in est et odio cursus vestibulum. Duis nec
Code: Select all
ssqvplfQrsL
aoueroeuhoo
glanibuiodr
ilmemogsnae
ti.niriqclm
tc astauue
iiDt itessi
stoiis .p
unsn.nie s
ede. udnIu
tic fMl inm
n Caollm
l sruraa.md
aauacb,c oo
c ssii uVll
urc b vsilo
shioume vir
oprsolaas
nnin l tm s
ectaolt ufi
cu rrirnsrt
,stecsiu i
u i sltna
airi btligm
cnppliianie
c,isubq clt
u suceulil,
mc mtneada
sua ud ou c
ar asuarnvo
nsec mueton
ur e ge ls
fsodtautaue
r so ne rtc
iv lut mcpt
niuoleeauae
gtlrt gl tt
ial reeem.u
leacigssi r
l mocetu,U
alcnetaa ta
oogs sds d
lrru p aiui
iepephv ttp
bme oaev i
e.rasrliacs
r ,uue.tmoc
oI cet aeni
.nvtrrCetdn
ioeau ig
Nftr .rafm
aea.c aleee
mue uDbiunl
g Pboiqgti
iilhintuiut
naoaleuaam.
tbsicrmt
e oea nQ
sprl epttuu
totlCureuli
siuu elrls
eussrltlpaq
te aoiui,u
reveruss e
oeri;em. a
d ot m sca
ifsaE mPu
oe etlaests
rs ieulcie
cmopaorlinm
uedlm.iepc
rnaa sniie
stlchV ttdu
uueeeece ui
smsrnsusvns
..adtrqetm
v trisul o
eNC ebue.ld
sursrus e
tlaeil vNcm
ilsmtudeuta
ba . mohlug
u l a lilsn
lloUraoca.a
uartcnru
mce ut lcMc
.ume etaoao
s ta r nun
D o iilvrs
umdlppsaaie
ieioostolsq
storruirl u
u,etmqeiaa
ns ma ues t
e, et
c
-
- New poster
- Posts: 2
- Joined: Mon Aug 27, 2012 12:15 pm
Re: 490 - Rotating Sentence
I'm getting WA.
Here's my code.. What's wrong with it?

Here's my code.. What's wrong with it?

Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
char s[102][102],found;
int i,j,len,maxl;
for(i = 0; i < 102;++i)
{
for(j = 0; j < 102; ++j)
s[i][j] = ' ';
}
for(i = maxl = 0;gets(s[i]);++i)
{
if(strlen(s[i]) > maxl)
maxl = strlen(s[i]);
}
len = i-1;
for(j = 0,found = 1; found == 1; ++j)
{
for(i = len,found = 0; i >= 0; --i)
{
if(j < maxl)
{
found = 1;
putchar(s[i][j]);
}
}
if(found == 1)
putchar('\n');
}
return 0;
}
Re: 490 - Rotating Sentence
Your code fails on the sample input (given in the problem statement). Try taking the sample input provided two posts above yours and run your program. Compare the output with the AC output provided.s.mahzabin wrote:I'm getting WA.![]()
Here's my code.. What's wrong with it?
Also, next time, consider reading the thread carefully. It exists for a reason. Often times, you'll find useful information - including test cases that others have posted.
Re: 490 - Rotating Sentence
Anyone know if it's necessary to actually read in the newlines (like maybe the judge input has a mix of lines with and without carriage returns)?
I'm doing it in Java and my output matches the sample output, with spaces to pad the ends of output lines (that is, I'm printing a perfect rectangle, bound by the number of lines read in and the length of the longest line read in).
I've tried it a number of ways: without the padding at the ends of lines, with an extra newline at the end, with an extra line of spaces at the end (like in your sample output, v1n1t -- should there be an extra space at the end of the last line in your input? I'm confused), and nothing seems to work.
Closest I came was when I actually had a bug (wasn't printing spaces on the left when ending input rows are short) and I got PE. But I feel like I've tried it every which way at this point, short of trying to save the newline characters, and nothing's passed. I think on my next attempt I'm going to make sure I'm going to use OS-dependent newline behavior, but I've never had to do that before, and don't know what else it could be.
I'm using diff to test my output, so I don't think there are any stray null characters.
If anyone's interested, my code is here: https://gist.github.com/johncip/9de5a3bbaea4225f34bc
(This version does not print an extra line at the end.)
Nevermind, just realized it doesn't work with brianfry's input (skips the zeros!?). Off to figure out why...
I'm doing it in Java and my output matches the sample output, with spaces to pad the ends of output lines (that is, I'm printing a perfect rectangle, bound by the number of lines read in and the length of the longest line read in).
I've tried it a number of ways: without the padding at the ends of lines, with an extra newline at the end, with an extra line of spaces at the end (like in your sample output, v1n1t -- should there be an extra space at the end of the last line in your input? I'm confused), and nothing seems to work.
Closest I came was when I actually had a bug (wasn't printing spaces on the left when ending input rows are short) and I got PE. But I feel like I've tried it every which way at this point, short of trying to save the newline characters, and nothing's passed. I think on my next attempt I'm going to make sure I'm going to use OS-dependent newline behavior, but I've never had to do that before, and don't know what else it could be.
I'm using diff to test my output, so I don't think there are any stray null characters.
If anyone's interested, my code is here: https://gist.github.com/johncip/9de5a3bbaea4225f34bc
(This version does not print an extra line at the end.)
Nevermind, just realized it doesn't work with brianfry's input (skips the zeros!?). Off to figure out why...
Re: 490 - Rotating Sentence
Hang in there. It can be very frustrating when the problem's straightforward and getting the output right's a challenge.johncip wrote:I've tried it a number of ways: without the padding at the ends of lines, with an extra newline at the end, with an extra line of spaces at the end (like in your sample output, v1n1t -- should there be an extra space at the end of the last line in your input? I'm confused), and nothing seems to work.
I did a cursory check and your code looks good. I'm sorta pressed for time and can't debug in detail now but I'll circle back later (and try to provide an answer to your question).
Just wanted to tell you to keep the faith. It'll work out. Sometimes trying something else in the meantime really helps.
EDIT:
Yep. Just now saw that too. It does work fine though if the input's like soNevermind, just realized it doesn't work with brianfry's input (skips the zeros!?). Off to figure out why...
Input:
Code: Select all
Rene Decartes once said,
"I think, therefore I am."
a
b
abcd
abcdefghijklmnopqrstuvwxyz
hellobonjourholanamaskaramnihao
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890