490 - Rotating Sentences
Moderator: Board moderators
-
- New poster
- Posts: 24
- Joined: Fri Oct 24, 2008 8:37 pm
- Location: CUET, Chittagong, Bangladesh
- Contact:
Re: 490-Rotating sentence
Thanks kabir bhai.
Last edited by aliahmed on Wed Apr 22, 2009 10:47 pm, edited 1 time in total.
Re: 490-why WA
it is giving right output for possible inputs but why WA
here is my code:
please help somebody 
here is my code:
Code: Select all
#include<stdio.h>
#include<string.h>
#define MAX 500
char str1[MAX][500];
int main()
{
char line[100001];
long j=0,i,k,temp,len;
while(gets(line)){
len=strlen(line);
if(len>temp)temp=len;
strcpy(str1[j++],line);
}
for(i=0;i<temp;i++){
for(k=j-1;k>=0;k--){
printf("%c",str1[k][i]);
}
printf("\n");
}
return 0;
}

i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
Re: 490-why WA
Hi, your solution don't even pass the sample test cases.
In the sample output we have:
where I replaced the blanks with asterisks.
But your code gives:
I think that is the problem:)
In the sample output we have:
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,
.
"
But your code gives:
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,
.*
"*
-
- Experienced poster
- Posts: 103
- Joined: Tue Mar 25, 2008 11:00 pm
- Location: IUT-OIC, DHAKA, BANGLADESH
- Contact:
Re: 490-why WA
I wonder how this code got WA. it should get RE coz...the variable tem.abid_iut wrote:it is giving right output for possible inputs but why WA
here is my code:
Code: Select all
long j=0,i,k,temp,len; while(gets(line)){ len=strlen(line); if(len>temp)temp=len; strcpy(str1[j++],line); }
tem need to be initialized before comparing with len....
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................
It is more tough to become a good person.
I am trying both...............................
Re: 490-why WA
Actually, it's quite likely that temp would be initialized to zero: he has declared a rather large array just before it, so most of the changes on program's stack before main() is called would happen only in the beginning of that array, and temp would be the value used to fill memory allocated for stack, i.e. zero.kbr_iut wrote:I wonder how this code got WA. it should get RE coz...the variable tem.
tem need to be initialized before comparing with len....
The problem, as gba356 already noticed, is that the code prints extra blanks sometimes. And those are not even spaces, but \0's.
Re: 490-Rotating sentence now PE makes me crazy
Before it was WA i changed my code and do what the previous posts told me to do
but now it becomes PE
please help
my code again:
but now it becomes PE
please help
my code again:
Code: Select all
#include<stdio.h>
#include<string.h>
#define MAX 500
char str1[MAX][500];
int main()
{
char line[100001];
long j=0,i,k,temp=0,len;
while(gets(line)){
len=strlen(line);
if(len>temp)temp=len;
strcpy(str1[j++],line);
}
for(i=0;i<temp;i++){
for(k=j-1;k>=0;k--){
if(str1[k][i]!=NULL){
if(k==j-1 && str1[k][i]==' '){continue;}
else
printf("%c",str1[k][i]);
}
}
printf("\n");
}
return 0;
}
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
Re: 490-Rotating sentence
Still your code generates incorrect output for the sample input.
Why did you ignore the spaces in the first column?
All you have to ignore are the spaces redundant at the end of the line.
This line may help you:
Keep working:)
Why did you ignore the spaces in the first column?
All you have to ignore are the spaces redundant at the end of the line.
This line may help you:
Code: Select all
freopen("out.txt","w",stdout);
Re: 490 : why WA with this simple looking problem?
Please tell me why m i getting PE?
For example if input is
Output is :
where * denotes a space
Code: Select all
Got AC
sorry to say but there are more confusing posts on this than clarifying.
we simply have to print the matrix as such.
If there is nuthing to print print a space.
Code: Select all
aaa aaa
aaa
aaa
aaa
a
aaaaaaaaaaaaaaaaaaaaaaa
where * denotes a space
Code: Select all
a**a*a
a**a*a
a**a*a
a*****
a*****
a*****
a*****
a*****
a*****
a*a***
a*a***
a*a***
a*****
a*****
a*****
a*****
a*****
aa****
a*****
a*****
a***aa
a***aa
a***aa
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 490 : why WA with this simple looking problem?
my code P.E.
someone help
someone help
Code: Select all
#include<stdio.h>
#include<memory.h>
int main()
{
int i=0,j,k;
char str[100][100];
int flag[100];
memset(flag,0,sizeof(flag));
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//len=0;
while(gets(str[i]))
{
i=i+1;
}
/* for(j=0;j<i;j++)
{
puts(str[j]) ;
}
*/
for(k=0;k<100;k++)
{
for(j=i-1;j>=0;j--)
{
if(str[j][k]=='\0')
flag[j]=1;
if(flag[j]==0)
printf("%c",str[j][k]);
}
printf("\n");
}
return 0;
}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 490 : why WA with this simple looking problem?
PE usually means that you print (or failed to print) trailing spaces on some lines in the output.
See the input/output posted just above by fR0D, your program doesn't seem to pass it.
Also, 'char str[100][100]' isn't enough to store the input in case of max test.
See the input/output posted just above by fR0D, your program doesn't seem to pass it.
Also, 'char str[100][100]' isn't enough to store the input in case of max test.
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
now WA: 490 - Rotating Sentences
now i got wrong answer??
i changed >-
so that it can print trailing space.
but WA.
anyone help??
i changed >-
Code: Select all
if(flag[j]==0)
printf("%c",str[j][k]);
to
if(flag[j]==0)
printf("%c",str[j][k]);
else if(flag[j]==1)
printf(" ");
but WA.
anyone help??
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 490 - Rotating Sentences
Dear all,
I got a Wrong Answer on that problem, also I do not see what exactly is wrong. For simplicity I post here the code where each output line is the same length, i.e., there might be too many spaces in the end. What bothers me more is the following: the output on the command line is different from the output when I redirect it to some file. How can this happen?
For the input file
the command line "rot-seq.exe < input" shows the right answer. But if I redirect it to a file "rot-seq.exe < input > output" then the output file looks like this
Why??
Thanks in advance,
Philipp
I got a Wrong Answer on that problem, also I do not see what exactly is wrong. For simplicity I post here the code where each output line is the same length, i.e., there might be too many spaces in the end. What bothers me more is the following: the output on the command line is different from the output when I redirect it to some file. How can this happen?
Code: Select all
#include <iostream>
using namespace std;
#include <string>
#include <vector>
int main() {
int n,max;
string line;
vector<string> input;
max=0; //maximum length of a line
n=0; //number of lines
while (getline(cin,line)) {
input.push_back(line);
n++;
if (line.size()>max)
max = line.size();
}
for (int j=0; j<max; j++) {
for (int i=n-1; i>=0; i--) {
if (input[i].size()<j)
cout << " ";
else
cout << input[i][j];
}
cout << endl;
}
return 0;
}
Code: Select all
aa
b
Code: Select all
ba
Thanks in advance,
Philipp
Re: 490 - Rotating Sentences
Your programs outputs a NUL character, so what you see is probably a reaction of your terminal software to that character.
Here's what I see:
Here's what I see:
Code: Select all
/tmp$ g++ -o p p.cc
/tmp$ (echo aa; echo b) | ./p
ba
a
/tmp$ (echo aa; echo b) | ./p | hexdump -C
00000000 62 61 0a 00 61 0a |ba..a.|
00000006
/tmp$
Re: 490 - Rotating Sentences
Ah, thank you! I could resolve my problems with your hint. At some point I tried to write a character from the string at a position which is out of boundary. This yields the NUL-character. The corrected test for that, substitute < with <=, resolved the problem. Thus my code is now accepted.
-
- New poster
- Posts: 25
- Joined: Fri Apr 17, 2009 8:24 am
Re: 490 - Rotating Sentences
Code: Select all
removed after AC
Last edited by asif_khan_ak_07 on Mon Sep 28, 2009 7:59 am, edited 1 time in total.