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

hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

Re: 490 - Rotating Sentences

Post by hello » Fri Jul 12, 2013 3:38 pm

Thanks for your reply . . . . . . .

marufsharif
New poster
Posts: 6
Joined: Sun Jul 21, 2013 1:36 pm

490 - Rotating Sentence

Post by marufsharif » Wed Jul 24, 2013 1:35 pm

.
Last edited by marufsharif on Mon Jul 29, 2013 12:30 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentence

Post by brianfry713 » Wed Jul 24, 2013 11:03 pm

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!

marufsharif
New poster
Posts: 6
Joined: Sun Jul 21, 2013 1:36 pm

Re: 490 - Rotating Sentence

Post by marufsharif » Thu Jul 25, 2013 9:45 am

thanks
Last edited by marufsharif on Mon Jul 29, 2013 12:30 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentence

Post by brianfry713 » Sat Jul 27, 2013 12:20 am

Print a newline at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

marufsharif
New poster
Posts: 6
Joined: Sun Jul 21, 2013 1:36 pm

Re: 490 - Rotating Sentence

Post by marufsharif » Sun Jul 28, 2013 7:28 am

Post Remove, After Accept
Last edited by marufsharif on Mon Jul 29, 2013 12:28 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentence

Post by brianfry713 » Mon Jul 29, 2013 4:46 am

Try input:

Code: Select all

1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Check input and AC output for thousands of problems on uDebug!

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: 490 - Rotating Sentence

Post by Shihab » Mon Feb 17, 2014 7:24 pm

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


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentence

Post by brianfry713 » Tue Feb 18, 2014 8:44 pm

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!

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

Re: 490 - Rotating Sentence

Post by uDebug » Sat Feb 22, 2014 1:15 pm

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:

Code: Select all

Rene Decartes once said,
"I think, therefore I am."
AC Output:

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

Find us on Facebook. Follow us on Twitter.

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

Re: 490 - Rotating Sentence

Post by uDebug » Sat Feb 22, 2014 1:22 pm

Here's some input / output to make things clearer in regards to the spaces.

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
AC Output:

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

Find us on Facebook. Follow us on Twitter.

s.mahzabin
New poster
Posts: 2
Joined: Mon Aug 27, 2012 12:15 pm

Re: 490 - Rotating Sentence

Post by s.mahzabin » Sat Mar 08, 2014 6:11 am

I'm getting WA. :(
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;
}

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

Re: 490 - Rotating Sentence

Post by uDebug » Sat Mar 08, 2014 9:21 am

s.mahzabin wrote:I'm getting WA. :(
Here's my code.. What's wrong with it? :-?
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.

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.
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 » Fri May 09, 2014 9:04 am

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

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

Re: 490 - Rotating Sentence

Post by uDebug » Fri May 09, 2014 9:26 am

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.
Hang in there. It can be very frustrating when the problem's straightforward and getting the output right's a challenge.

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:
Nevermind, just realized it doesn't work with brianfry's input (skips the zeros!?). Off to figure out why...
Yep. Just now saw that too. It does work fine though if the input's like so

Input:

Code: Select all

Rene Decartes once said,
"I think, therefore I am."
a
b
abcd
abcdefghijklmnopqrstuvwxyz
hellobonjourholanamaskaramnihao
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 4 (400-499)”