Page 9 of 15

Re: 490-Rotating sentence

Posted: Fri Nov 14, 2008 10:28 pm
by aliahmed
Thanks kabir bhai.

Re: 490-why WA

Posted: Sat Nov 22, 2008 8:07 pm
by abid_iut
it is giving right output for possible inputs but why WA
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;
}
please help somebody :cry:

Re: 490-why WA

Posted: Sun Nov 23, 2008 3:12 am
by gba356
Hi, your solution don't even pass the sample test cases.

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,
.
"
where I replaced the blanks with asterisks.

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,
.*
"*
I think that is the problem:)

Re: 490-why WA

Posted: Sun Nov 23, 2008 3:53 am
by kbr_iut
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);
	}
I wonder how this code got WA. it should get RE coz...the variable tem.
tem need to be initialized before comparing with len....

Re: 490-why WA

Posted: Mon Nov 24, 2008 8:29 am
by mf
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....
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.

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

Posted: Tue Nov 25, 2008 9:37 am
by abid_iut
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:

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

Re: 490-Rotating sentence

Posted: Thu Nov 27, 2008 4:18 am
by gba356
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:

Code: Select all

freopen("out.txt","w",stdout);
Keep working:)

Re: 490 : why WA with this simple looking problem?

Posted: Wed Dec 10, 2008 3:46 pm
by fR0D
Please tell me why m i getting PE?

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.
For example if input is

Code: Select all

aaa                 aaa
                    aaa
aaa
         aaa
                 a
aaaaaaaaaaaaaaaaaaaaaaa
Output is :
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

Re: 490 : why WA with this simple looking problem?

Posted: Thu Jan 29, 2009 10:52 pm
by sazzadcsedu
my code P.E.
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;

						}

Re: 490 : why WA with this simple looking problem?

Posted: Fri Jan 30, 2009 12:42 am
by mf
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.

now WA: 490 - Rotating Sentences

Posted: Sat Jan 31, 2009 8:47 pm
by sazzadcsedu
now i got wrong answer??
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(" ");
                                   
so that it can print trailing space.
but WA.
anyone help??

Re: 490 - Rotating Sentences

Posted: Thu Aug 06, 2009 12:20 am
by zuphilip
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?

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;
}
For the input file

Code: Select all

aa
b
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

Code: Select all

ba
  
Why??

Thanks in advance,
Philipp

Re: 490 - Rotating Sentences

Posted: Thu Aug 06, 2009 8:58 am
by mf
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:

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

Posted: Thu Aug 06, 2009 10:21 am
by zuphilip
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.

Re: 490 - Rotating Sentences

Posted: Mon Aug 10, 2009 7:50 pm
by asif_khan_ak_07

Code: Select all

removed after AC