490 - Rotating Sentences
Moderator: Board moderators
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
What if count[j] = len[j][0]?
Reconsider this and I think you are done.
Good Luck
Mahfuz
-
- New poster
- Posts: 25
- Joined: Fri Apr 17, 2009 8:24 am
Re: 490 - Rotating Sentences
Thank You.....I got AC 

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!
Re: 490 - Rotating Sentences
Could anyone help?
I think I satisfy the requirement.
But I always get WA
Thank you
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;
}
-
- 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--)"....
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;
}
}
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
I hope that somebody can help me 

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

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

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

-
- 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
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
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 ;
}
-
- 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;
}
#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;
}
-
- Learning poster
- Posts: 96
- Joined: Tue Jul 19, 2011 12:19 pm
- Location: Dhaka, Bangladesh
- 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;
}
-
- 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.
Post to an existing thread about a problem.
Check input and AC output for thousands of problems on uDebug!