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

assasin
New poster
Posts: 7
Joined: Wed Feb 13, 2008 3:59 pm

### Re: 490 - Rotating Sentences

Do you think if(count[j]>len[j][0]) is ok?

What if count[j] = len[j][0]?
Reconsider this and I think you are done.

Good Luck

Mahfuz

asif_khan_ak_07
New poster
Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

### Re: 490 - Rotating Sentences

Thank You.....I got AC

RoMeLuKo
New poster
Posts: 7
Joined: Mon Jan 02, 2006 1:44 am
Location: Puno - Peru
Contact:

### Re: 490 runtime error

I had the same problem, solution was allocate space for 101 sentences, not 100 like problem said.
Last edited by RoMeLuKo on Fri Nov 06, 2009 5:04 pm, edited 1 time in total.
Luck!

kaffir
New poster
Posts: 1
Joined: Tue Nov 10, 2009 9:57 am

### Re: 490 - Rotating Sentences

Could anyone help?
I think I satisfy the requirement.
But I always get WA
Thank you

Code: Select all

``````#include <iostream>
#include <cstring>
using namespace std;

int main()
{
char input[101][101] = {'\0'};
int totSen = 0, totRow = 0;
int row = 0, col = 0;
int maxLen = 0;

while(!cin.eof())
{
cin.getline(input[totSen], 101);
totSen++;
}

cout << endl;

//Find the length.
for(int i = 0; i < totSen; i++)
{
int len = strlen(input[i]);

if(maxLen < len)
{
maxLen = len;
}
}

while(row < maxLen)
{
for(col = totSen-1; col >= 0 ; col--)
{
if(input[col][row] != '\0' )
{
cout << input[col][row];
}
else
{
cout << ' ';
}
}

cout << endl;

row++;
}

return 0;
}
``````

mostafa_angel
New poster
Posts: 23
Joined: Sun Oct 04, 2009 12:03 pm

### Re: 490 - Rotating Sentences

kaffir wrote:Could anyone help?
I think I satisfy the requirement.
But I always get WA
Thank you

Code: Select all

``````#include <iostream>
#include <cstring>
using namespace std;

int main()
{
char input[101][101] = {'\0'};
int totSen = 0, totRow = 0;
int row = 0, col = 0;
int maxLen = 0;

while(!cin.eof())
{
cin.getline(input[totSen], 101);
totSen++;
}

cout << endl;

//Find the length.
for(int i = 0; i < totSen; i++)
{
int len = strlen(input[i]);

if(maxLen < len)
{
maxLen = len;
}
}

while(row < maxLen)
{
for(col = totSen-1; col >= 0 ; col--)
{
if(input[col][row] != '\0' )
{
cout << input[col][row];
}
else
{
cout << ' ';
}
}

cout << endl;

row++;
}

return 0;
}
``````

it is clear !
in the problem test case you have 2 sentences for rotating but the your counter is 3 and when you want to print them at the first column you print a blank sentence !
this line "for(col = totSen-1; col >= 0 ; col--)" must be changes to "for(col = totSen-2; col >= 0 ; col--)"....

doitnow
New poster
Posts: 2
Joined: Thu Jan 28, 2010 5:03 am

### 490 - Rotating Sentences ????????????

how can i get through the judge ?? pls help me work this out.

Code: Select all

``````

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main()
{
vector<string> buffer;
vector<string>::iterator itor ;
string str;
int count = 0;
while(getline(cin, str))
{
buffer.push_back(str);
}
count = buffer.size();
reverse(buffer.begin(), buffer.end());
while (true)
{
for (itor = buffer.begin(); itor != buffer.end(); itor ++)
{ // first test the string 's for sure it is not empty
if (itor->empty())
{
count --; cout << " ";
continue;
}
cout.put(itor->at(0));
itor->erase(0, 1);
}
cout << endl;
if (count == 0) break;
}
}

``````

KRUNCH
New poster
Posts: 8
Joined: Sun May 18, 2008 1:03 pm

### Re: 490 - Rotating Sentences

Hi , I'm getting PE on this task , I tried with and without a newline on the end of the output , I've got trailing spaces , I just don't get it

Code: Select all

``````#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
int fld[350][350];
for(int i=0;i<150;i++)
for(int j=0;j<150;j++)
fld[i][j]=' ';
int maxi=0,n=0;
string r;
while(!cin.eof())
{
getline(cin,r);
if(maxi<r.size())maxi=r.size();
for(int i=0;i<r.size();i++)
{
fld[n][i]=r[i];
}
n++;
}
for(int j=0;j<maxi;j++)
{
for(int i=n-1;i>=0;i--)
{
cout<<char(fld[i][j]);
}
cout<<endl;
}
}
``````
I hope that somebody can help me

iceb3rg
New poster
Posts: 7
Joined: Mon Jul 13, 2009 11:30 am
Location: SUST - CSE
Contact:

### Re: 490 - Rotating Sentences

Hi, first of all with this problem I was confused about how to take the inputs. Finally I made up my mind to take all the inputs uptill the end of the file and then print them in the sequential manner told.

However, after doing so, I am getting WA.... Help me out here....

here's my code:

#include <stdio.h>
#include <string.h>

int main()
{
freopen("input4uva.txt","r",stdin);

char name[100][100];
char temp[100];

int i=0,j,k,l,max=0;

while (gets(temp)>0)
{
strcpy(name,temp);
l=strlen(name[i++]);

if (l>max)
max=l;

}

for (k=0;k<max;k++)
{
for (j=i-1;j>=0;j--)
printf ("%c",name[j][k]);

printf ("\n");
}

return 0;
}
still a lot to learn & a long long way to go....but I'll keep trying till I have lov 4 it

kawsar
New poster
Posts: 12
Joined: Thu Aug 05, 2010 7:40 pm

### 490 wrong answer

#include<stdio.h>
#include<string.h>

int main(){
char a[1000][1000], x[1000], c ;
int i=0, p=0, j, k, n ;

while (c = getchar ()) {
if (c == EOF)
return 0;
n = 0 ;

x[n++] = c ;

while((c=getchar()) != '\n')
x[n++] = c ;
x[n] = '\0' ;

if(strlen(x) > p)
p = strlen(x) ;

strcpy(a,x);
i++ ;
}

for(j=0; j<i; j++){
if(strlen(a[j]) < p){
n = strlen(a[j]) ;

for(k=n; k<p; k++)
a[j][k] = 32 ;
a[j][k] = '\0' ;
}
}

for(k=0; k<p; k++){
for(j=i-1; j>=0; j--)
printf("%c",a[j][k]);
printf("\n");
}
return 0;
}

i don't understand the, why i got WA.

kawsar
New poster
Posts: 12
Joined: Thu Aug 05, 2010 7:40 pm

### Re: 490 - Rotating Sentences

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){
char a[1000][1000], x[1000], c ;
int i=0, p=0, j, k, n ;

while (c = getchar ()) {
if (c == EOF)
return 0;
n = 0 ;

if(isalpha(c))
x[n++] = c ;

while((c=getchar()) != '\n')
if(isalpha(c))
x[n++] = c ;
x[n] = '\0' ;

if(strlen(x) > p)
p = strlen(x) ;

strcpy(a,x);
i++ ;
}

for(j=0; j<i; j++){
if(strlen(a[j]) < p){
n = strlen(a[j]) ;

for(k=n; k<p; k++)
a[j][k] = 32 ;
a[j][k] = '\0' ;
}
}

for(k=0; k<p; k++){
for(j=i-1; j>=0; j--)
printf("%c",a[j][k]);
printf("\n");
}
return 0;
}

I don't understand why i getting Wrong Answer every time.

Can anyone help me to find out the error of this problem... ???

mustak0715
New poster
Posts: 3
Joined: Tue Oct 26, 2010 3:42 am

### 490 when input stops???

when will be the input stops?
tell me.
my code....
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{

char a[100][100];

int max=0;
int flagnull[100];
int i=0;
while(gets(a))

{
if(a[strlen(a)-1]==9)
{

if(strlen(a)<=1)
break;
a[strlen(a)-1]='\0';

i++;
break;
}
i++;
}
max=i;
int maxlength;
maxlength=strlen(a[0]);

for(i=1;i<max;i++)
if(maxlength<strlen(a))
maxlength=strlen(a);
for(int J=0;J<maxlength;J++)
{
for(i=max-1;i>=0;i--){

if(a[J]=='\0')
flagnull=1;
if(flagnull[i]==1)
{

printf(" ");
continue;
}
printf("%c",a[i][J]);

}cout<<endl;
}
return 0;
}

where is error
why get WA

dewsworld
New poster
Posts: 12
Joined: Fri Aug 13, 2010 11:52 am

### Re: 490 - Rotating Sentences

Can anyone help me with this code? I get WA with it, still ignore of why...

Code: Select all

``````#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std ;

int main()
{
//    freopen("in.txt", "r", stdin) ;

vector<string>in ;
string  t ;
int     i, j, max ;

while( getline(cin, t ) )
{
in.push_back(t) ;

// Find max length of them
max = 0 ;
for( i=0; i<in.size(); i++ )
if( in[i].length() > max ) max = in[i].length() ;

// Now resize all upto MAX
for( i=0; i<in.size(); i++ )
in[i].resize(max) ;
}

// Now the odd coding :<
for( i=0; i<max; i++ )
{
for( j=in.size()-1; j>=0; j--)
cout << in[j][i] ;

cout << endl ;
}

return 0 ;
}
``````

asmahaque_456
New poster
Posts: 1
Joined: Thu May 19, 2011 2:50 pm

### 490-Rotating Sentences

Can anyone tell me why am i getting WA

#include<stdio.h>
#include<string.h>
int main()
{
int i,j,len=0,k;
char ch[30];
freopen("resent.txt","r",stdin);
freopen("ot.txt","w",stdout);
char str[20][1][30];
for(i=0;i<10;i++)
{
for(j=0;j<30;j++)
{
str[0][j]='\0';
}
}
j=0;
while(gets(ch))
{
strcpy(str[j][0],ch);
k=strlen(ch);
if(k>len)len=strlen(ch);
j++;
}
for(i=0;i<len;i++)
{
for(k=j-1;k>=0;k--)
{
printf("%c",str[k][0]);
}
printf("\n");
}

return 0;
}

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Contact:

### 490 - Rotating Sentences why? WA please help me

Anyone help me please, or give me some test cases.

Code: Select all

``````#include<stdio.h>
#include<string.h>
int main()
{

char s1[1001]={'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
char s2[1001]={'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'};
//freopen("in","r",stdin);
while(gets(s1))
{
int max,len1,len2;
//if(s1[0]=='\0')
{
//gets(s1);
len1=strlen(s1);
}
if(s2[0]=='\0' && s1[0]!='\0')
{
gets(s2);
len2=strlen(s2);
}

if(len1>len2)
{
max=len1;
for(int i=len2 ; i<max ; i++)
{
s2[i]='\0';
}
}

else if(len2>len1)
{
max=len2;
for(int i=len1 ; i<max ; i++)
{
s1[i]='\0';
}
}
else
max=len1;

int fag=0;
for(int i=0 ; i<max ; i++)
{
printf("%c%c\n",s2[i],s1[i]);
fag++;
}

if(fag!=0)
{
for(int i=0 ; i<max ; i++)
{
s1[i]='\0';
s2[i]='\0';
}
}

}
return 0;
}

``````

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

### Re: 490 - Rotating Sentences why? WA please help me

You're assuming there are always two sentences, there could be up to 100. You also can't print an extra null character at the end of a line.

Post to an existing thread about a problem.
Check input and AC output for thousands of problems on uDebug!