Re: 490 - Rotating Sentences
Posted: Fri Jul 12, 2013 3:38 pm
Thanks for your reply . . . . . . .
Code: Select all
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
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;
}
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,
.
"
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
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;
}
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?
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.
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...
Code: Select all
Rene Decartes once said,
"I think, therefore I am."
a
b
abcd
abcdefghijklmnopqrstuvwxyz
hellobonjourholanamaskaramnihao
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890