Page 10 of 15

### Re: 490 - Rotating Sentences

Posted: Mon Sep 14, 2009 5:36 am
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

### Re: 490 - Rotating Sentences

Posted: Thu Sep 17, 2009 5:14 pm
Thank You.....I got AC

### Re: 490 runtime error

Posted: Tue Nov 03, 2009 4:21 am
I had the same problem, solution was allocate space for 101 sentences, not 100 like problem said.

### Re: 490 - Rotating Sentences

Posted: Tue Nov 10, 2009 10:02 am
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;
}
``````

### Re: 490 - Rotating Sentences

Posted: Wed Nov 18, 2009 1:52 pm
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--)"....

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

Posted: Thu Jan 28, 2010 5:18 am
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;
}
}

``````

### Re: 490 - Rotating Sentences

Posted: Sun Mar 28, 2010 5:44 pm
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

### Re: 490 - Rotating Sentences

Posted: Sat Apr 24, 2010 4:15 pm
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;
}

Posted: Thu Aug 05, 2010 7:58 pm
#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.

### Re: 490 - Rotating Sentences

Posted: Tue Aug 10, 2010 3:45 pm
#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... ???

### 490 when input stops???

Posted: Tue Oct 26, 2010 6:41 pm
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

### Re: 490 - Rotating Sentences

Posted: Sat Nov 27, 2010 6:58 pm
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 ;
}
``````

### 490-Rotating Sentences

Posted: Sat May 21, 2011 2:22 pm
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;
}

Posted: Wed Dec 28, 2011 5:37 am
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;
}

``````