490 - Rotating Sentences
Moderator: Board moderators
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Hmmm, that's strange ....
If I correct remember statements say, that spaces at end of line should be avoided .... (I got P.E. - maybe instead of that ?)
Dominik
If I correct remember statements say, that spaces at end of line should be avoided .... (I got P.E. - maybe instead of that ?)
Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
Problem 490
I got Wrong Answer
but I don't know why ><...
[cpp]
#include <iostream.h>
#include <string.h>
#include <stdio.h>
int main()
{
char data[101][101];
int msize;
int n,t,t2;
for (t=0 ;t<=100 ;t++)
data[0][t]=' ';
n=0;
// freopen ("482in.txt","r",stdin);
msize=0;
while (gets (data[n]))
{
if (strlen(data[n])>msize)
msize=strlen (data[n]);
n++;
for (t=0 ;t<=100 ;t++)
data[n][t]=' ';
}
for (t=0 ;t<msize ;t++)
{
for (t2=n-1 ;t2>=0 ;t2--)
cout << data[t2][t];
cout << endl;
}
return 0;
}
[/cpp]
Thanks!
but I don't know why ><...
[cpp]
#include <iostream.h>
#include <string.h>
#include <stdio.h>
int main()
{
char data[101][101];
int msize;
int n,t,t2;
for (t=0 ;t<=100 ;t++)
data[0][t]=' ';
n=0;
// freopen ("482in.txt","r",stdin);
msize=0;
while (gets (data[n]))
{
if (strlen(data[n])>msize)
msize=strlen (data[n]);
n++;
for (t=0 ;t<=100 ;t++)
data[n][t]=' ';
}
for (t=0 ;t<msize ;t++)
{
for (t2=n-1 ;t2>=0 ;t2--)
cout << data[t2][t];
cout << endl;
}
return 0;
}
[/cpp]
Thanks!
490 - Rotating Sentences [WA]
I cannot find out what is wrong with my code... can anyone help me and take a look?
Many thanks!
[c]
#include <iostream.h>
#include <stdio.h>
int main()
{
char chArr[200][200];
char **chOut;
char chIn;
int I, J;
int K, L;
int intLines;
int intLongest = 0;
bool firstchar = true;
//freopen("test_in.txt","r",stdin);
//freopen("test_out.txt","w",stdout);
for (I = 0; I < 100; I++)
{
for (J = 0; J < 100; J++)
chArr[J] = '\0';
}
I = J = 0;
intLines = 0;
while (scanf("%c",&chIn)==1)
{
if (chIn == '\t' || chIn == '\r')
continue;
if (chIn == '\n')
{
J++;
intLines++;
I = 0;
continue;
}
chArr[J] = chIn;
I++;
if (I > intLongest)
intLongest = I;
}
intLines += 1;
chOut = new char*[intLines];
for (I = 0; I < intLines; I++)
chOut = new char[intLongest];
K = L = 0;
for (I = 0; I < intLongest; I++)
{
K = 0;
for (J = intLines - 1; J >=0; J--)
{
chOut[K][L] = chArr[J];
K++;
}
L++;
}
for (I = 0; I < intLongest; I++)
{
for (J = 0; J < intLines; J++)
cout << chOut[J];
if (I != intLongest - 1)
cout << endl;
}
return 0;
}
[/c]
Many thanks!
[c]
#include <iostream.h>
#include <stdio.h>
int main()
{
char chArr[200][200];
char **chOut;
char chIn;
int I, J;
int K, L;
int intLines;
int intLongest = 0;
bool firstchar = true;
//freopen("test_in.txt","r",stdin);
//freopen("test_out.txt","w",stdout);
for (I = 0; I < 100; I++)
{
for (J = 0; J < 100; J++)
chArr[J] = '\0';
}
I = J = 0;
intLines = 0;
while (scanf("%c",&chIn)==1)
{
if (chIn == '\t' || chIn == '\r')
continue;
if (chIn == '\n')
{
J++;
intLines++;
I = 0;
continue;
}
chArr[J] = chIn;
I++;
if (I > intLongest)
intLongest = I;
}
intLines += 1;
chOut = new char*[intLines];
for (I = 0; I < intLines; I++)
chOut = new char[intLongest];
K = L = 0;
for (I = 0; I < intLongest; I++)
{
K = 0;
for (J = intLines - 1; J >=0; J--)
{
chOut[K][L] = chArr[J];
K++;
}
L++;
}
for (I = 0; I < intLongest; I++)
{
for (J = 0; J < intLines; J++)
cout << chOut[J];
if (I != intLongest - 1)
cout << endl;
}
return 0;
}
[/c]
Hello!
I've tested your program and found that it suffers from Presentation Errors. So I would suggest the following modifications:
1. Delete line 46: intLines += 1;
2. Delete line 72: if (I != intLongest - 1)
Try it and get AC!
I've tested your program and found that it suffers from Presentation Errors. So I would suggest the following modifications:
1. Delete line 46: intLines += 1;
2. Delete line 72: if (I != intLongest - 1)
Try it and get AC!
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
490 wa, plizzzzzzzzzzzzzzz help me :(:(:(
i am having trouble with 490, i am getting wa all the time.here is my code plizzzzzz help.
thanx in advance
Riyad
thanx in advance
Riyad







Code: Select all
#include<stdio.h>
#include<string.h>
#define row 100
#define col 110
char input[row][col];
int index=0;
int max_count(){
int i ;
int max=0;
for(i=0;i<index;i++){
if(strlen(input[i])>max){
max=strlen(input[i]);
}
else
continue;
}
return max;
}
void print(int max){
int i ,j;
for(i=0;i<max;i++){
for(j=index-1;j>=0;j--){
if(i>=strlen(input[j]))
continue;
else
printf("%c",input[j][i]);
}
printf("\n");
}
}
int main(){
int max;
freopen("input.in","rt",stdin);
while(gets(input[index++])){
;
}
max=max_count();
print(max);
return 0;
}
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
INPUT
YOUR OUTPUT
EXPECTED OUTPUT
Code: Select all
test
test test
test test test
test test
test
Code: Select all
ttttt
eeeee
sssss
ttttt
ttt
eee
sss
ttt
t
e
s
t
Code: Select all
ttttt
eeeee
sssss
ttttt
ttt
eee
sss
ttt
t
e
s
t
still wa:(:(:( plizzzzzzzzzzzzzzzzzz help
i adjusted what u have told about my program . i printed a space instead of continuing when the string length is small . my program now prints the same as the sample out put of urs. but still having wa.
.plizzzzzzzzzzzzzz help me .
here is my code :
thanx is advance
Riyad






here is my code :



Code: Select all
#include<stdio.h>
#include<string.h>
#define row 100
#define col 110
char input[row][col];
int index=0;
int max_count(){
int i ;
int max=0;
for(i=0;i<index;i++){
if(strlen(input[i])>max){
max=strlen(input[i]);
}
else
continue;
}
return max;
}
void print(int max){
int i ,j;
for(i=0;i<max;i++){
for(j=index-1;j>=0;j--){
if(i>=strlen(input[j])){
changed here!!--------------------------------------->printf(" ");
/**************************************************/
//continue;
}
else
printf("%c",input[j][i]);
}
printf("\n");
}
}
int main(){
int max;
freopen("input.in","rt",stdin);
while(gets(input[index++])){
;
}
max=max_count();
print(max);
return 0;
}
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
490 why WA???
hi! i have WA whu? plz help
[c]
#include <stdio.h>
#include <string.h>
main()
{
char tab[102][102];
int spr[102];
char t;
int i=0,n,max=0;
int j=0;
t=getchar();
while(t!=EOF)
{
char s;
j=0;
while (t!='\n' && t!=EOF)
{
if (t!='\t' && t!='\r'){
tab[j]=t;
j++;
}
t=getchar();
}
s=t;
t=getchar();
tab[j]='\0';
spr=1;
i++;
}
n=i;
for (i=0;i<n;i++)
if (max<strlen(tab))
max=strlen(tab);
for (i=0;i<max+1;i++)
{
int j;
for (j=n-1;j>=0;j--)
{
if (spr[j])
{
if (tab[j]!=0)
putchar(tab[j]);
else
{
spr[j]=0;
putchar(' ');
}
}
else
putchar(' ');
}
putchar('\n');
}
}
[/c]
[c]
#include <stdio.h>
#include <string.h>
main()
{
char tab[102][102];
int spr[102];
char t;
int i=0,n,max=0;
int j=0;
t=getchar();
while(t!=EOF)
{
char s;
j=0;
while (t!='\n' && t!=EOF)
{
if (t!='\t' && t!='\r'){
tab[j]=t;
j++;
}
t=getchar();
}
s=t;
t=getchar();
tab[j]='\0';
spr=1;
i++;
}
n=i;
for (i=0;i<n;i++)
if (max<strlen(tab))
max=strlen(tab);
for (i=0;i<max+1;i++)
{
int j;
for (j=n-1;j>=0;j--)
{
if (spr[j])
{
if (tab[j]!=0)
putchar(tab[j]);
else
{
spr[j]=0;
putchar(' ');
}
}
else
putchar(' ');
}
putchar('\n');
}
}
[/c]
WA, WA, WA!!
Why WA?
I've ever looked all posts about this problem, but none helped me.
[cpp]
#include <iostream.h>
#include <string.h>
void main()
{ char matriz[102][102];
int cont, max;
cont=0;
max=0;
while (cin.getline(matriz[cont],100,'\n'))
{ if (strlen(matriz[cont])>max) max=strlen(matriz[cont]);
cont++;
}
for (int i=0; i<max; i++)
{ for (int j=cont-1; j>=0; j--)
if (strlen(matriz[j])>i)
cout << matriz[j];
else cout << " ";
cout << endl;
}
}
[/cpp][/code]
I've ever looked all posts about this problem, but none helped me.
[cpp]
#include <iostream.h>
#include <string.h>
void main()
{ char matriz[102][102];
int cont, max;
cont=0;
max=0;
while (cin.getline(matriz[cont],100,'\n'))
{ if (strlen(matriz[cont])>max) max=strlen(matriz[cont]);
cont++;
}
for (int i=0; i<max; i++)
{ for (int j=cont-1; j>=0; j--)
if (strlen(matriz[j])>i)
cout << matriz[j];
else cout << " ";
cout << endl;
}
}
[/cpp][/code]
VIVA LEOPARDO SC!!
i got WA on 490, can you help me?
Here is my code... i tried to substitute '\0' in the array "str" with spaces but i still get WA. I saw some topics about 490 but i didn't found where i'm wrong... can you help me?
[c]
#include <stdio.h>
#include <string.h>
main()
{
char str[103][103]={'\0'};
int i=0,j,maxl=0,k,pos;
while( fgets(str,102,stdin) )
{
pos=(strlen(str)-1);
if (pos<0) pos=0;
if (str[pos]=='\n') str[pos]='\0'; /* Erases fgets' '\n'*/
if ( maxl<strlen(str) ) maxl=strlen(str);
++i;
}
--i;
for (k=0;k<maxl;k++)
{
for(j=i;j>=0;j--)
{
printf("%c",str[j][k]);
}
printf("\n");
}
}
[/c]
Thanks in advance!
[c]
#include <stdio.h>
#include <string.h>
main()
{
char str[103][103]={'\0'};
int i=0,j,maxl=0,k,pos;
while( fgets(str,102,stdin) )
{
pos=(strlen(str)-1);
if (pos<0) pos=0;
if (str[pos]=='\n') str[pos]='\0'; /* Erases fgets' '\n'*/
if ( maxl<strlen(str) ) maxl=strlen(str);
++i;
}
--i;
for (k=0;k<maxl;k++)
{
for(j=i;j>=0;j--)
{
printf("%c",str[j][k]);
}
printf("\n");
}
}
[/c]
Thanks in advance!
490 with WA~~~
I don't know where is wrong~~
Could anybody help me???
[c]#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i=-1,j=-1,k,l,max=0;
char ch[105][105],a;
while(scanf("%c",&a)!=EOF)
{
i++;
j=-1;
while(a!=10)
{
if(a!=9)
{
j++;
ch[j]=a;
}
scanf("%c",&a);
}
if(j>max)
max=j;
}
for(l=0;l<=max;l++)
{
for(k=i;k>=0;k--)
printf("%c",ch[k][l]);
printf("\n");
}
return 0;
}[/c]
Could anybody help me???
[c]#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i=-1,j=-1,k,l,max=0;
char ch[105][105],a;
while(scanf("%c",&a)!=EOF)
{
i++;
j=-1;
while(a!=10)
{
if(a!=9)
{
j++;
ch[j]=a;
}
scanf("%c",&a);
}
if(j>max)
max=j;
}
for(l=0;l<=max;l++)
{
for(k=i;k>=0;k--)
printf("%c",ch[k][l]);
printf("\n");
}
return 0;
}[/c]
in printing section add this code:
and make your array size little bigger
Note: problem statement is false, about input size!!
Code: Select all
for(k=i........)
{
if(ch[k][l]<='\0')
ch[k][l]=' ';
printf(.........);
}

Note: problem statement is false, about input size!!
