Page 6 of 15

Posted: Tue Dec 12, 2006 12:41 pm
by sakhassan
trailing spaces means spaces after the words ... for eg.

"Hello World........" where "." represents space :) ... Hope u understand .....

use 'gets' instead of 'scanf' .....

Posted: Thu Jan 18, 2007 10:03 pm
by Debashis Maitra
After a lot of PE finally i got AC

thnx jan bhai for his input

thnx everyone

Posted: Sat Feb 10, 2007 7:33 pm
by blodstone
I think I did waht all you guys post here, trailing spaces, new line etc but why still got PE? Someone help me please.

Code: Select all

#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
using namespace std;

int main(){
	freopen("input.in","r",stdin);
	freopen("output.out","w",stdout);
	vector<string> x;
	string buf;
	int i=0;
	int max=0;
	while(true){
		getline(cin,buf,'\n');
		i=buf.length();
		if(max<i) max=i;
		x.push_back(buf);
		if(feof(stdin)) break;	
	}
	for(int i=0;i<max;i++){
		for(int j=x.size()-1;j>=0;j--){
			if(i<x[j].length()){
				if(x[j][i]==32) cout << " ";
				else
				cout << x[j][i];
			}
			else
				cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Posted: Sun Feb 11, 2007 1:36 am
by Jan
Replace your code with the following part (you know where :D )...

Code: Select all

while(getline(cin,buf,'\n')){ 
      i=buf.length();
      if(max<i) max=i;
      x.push_back(buf);
   }
Hope it helps.

490 wa plz help

Posted: Mon Feb 19, 2007 5:59 pm
by S.M. Arifuzzaman
I don't know what's the wrong here. here's my code

Code: Select all

#include<stdio.h>

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("ot.txt","w",stdout);
	char arr[101][101]={' '},ch;
	int i=0,j=0,maxj=-1;   //maxj for maximum column length
	while(scanf("%c",&ch)!=EOF)
	{
		
		if(ch=='\n')
		{
			arr[i][j]=' ';
			i++;
			if(j>maxj)
				maxj=j;
			j=0;

		}
		

		else
		{
		
		
			arr[i][j]=ch;
			j++;
		
		
		}
			
	
	}
	j--;
	if(j>maxj)
				maxj=j;

	for(int m=0;m<=maxj;m++){
		for(int k=i;k>=0;k--)
			if(arr[k][m]!='\n')
				printf("%c",arr[k][m]);
		printf("\n");}



	return 0;
}
I have tried some sets of input posted in the forum by 'JAN' and 'mogers'
and got desired output. then why wrong????
I am so crazy now..... plz help(newcomer)

Posted: Mon Feb 19, 2007 6:18 pm
by helloneo
Hello..
If there is a thread already, don't create a new thread.. just use old one to post..

By the way, your array does not contain '\n'
What is this supposed to mean..?

Code: Select all

         if(arr[k][m]!='\n') 
            printf("%c",arr[k][m]); 

Posted: Mon Feb 19, 2007 7:16 pm
by S.M. Arifuzzaman
Initially i didn't substitute '\n' with ' '(space)<i think it was a mistake, isn't?>. so the two lines was included.
anyway then i substituted '\n' with ' '(space) but carelessly the two lines u indicated remained.
however, it is all the same the line "if(arr[k][m]!='\n')" remains or not. I just want to print arr[k][m]. Then why error?

***sorry for bad english

Posted: Tue Feb 20, 2007 8:15 am
by S.M. Arifuzzaman
Hi, I m a newcomer facing wa in 490, but don't know why. I have checked my code with some sets of input posted in the forum by 'JAN' etc. my code produces expected output. so why wa????

Code: Select all

#include<stdio.h>

int main()
{
	//freopen("in1.txt","r",stdin);
	//freopen("ot.txt","w",stdout);
	char arr[500][500]={' '},ch;
	int i=0,j=0,maxj=-1;   //maxj for maximum column length
	while(scanf("%c",&ch)!=EOF)
	{
		
		if(ch=='\n')
		{
			arr[i][j]=' ';
			i++;
			if(j>maxj)
				maxj=j;
			j=0;

		}
		

		else
		{
		
		
			arr[i][j]=ch;
			j++;
		
		
		}
			
	
	}
	j--;
	if(j>maxj)
				maxj=j;

	for(int m=0;m<=maxj;m++){
		for(int k=i;k>=0;k--)
			
				printf("%c",arr[k][m]);
		printf("\n");}



	return 0;
}

SO plz plz plz help me. I m getting crazy..........

Posted: Wed Feb 21, 2007 4:04 pm
by S.M. Arifuzzaman
:cry:
is there nobody to help me.
then what can i do?
what should be done now???
:( :( :( :( :( :( :( :( :( :(

Posted: Wed Feb 21, 2007 4:29 pm
by mf
Every line in input files, including the last one, is terminated by '\n'.
So, your program prints an unnecessary blank first column, that's why you get WA.

Posted: Wed Feb 21, 2007 6:46 pm
by S.M. Arifuzzaman
I hv done some modifications according to u(mf). but still wa. modifications are indicated in the code as comments.

Code: Select all

#include<stdio.h>

int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("ot.txt","w",stdout);
	char arr[1000][1000]={' '},ch;
	int i=0,j=0,maxj=-1;   //maxj for maximum column length
	while(scanf("%c",&ch)!=EOF)
	{
		
		if(ch=='\n')
		{
			//arr[i][j]=' ';  //modification 1
			i++;
			j--;   //modification 2:
                           //newly included as per mf to deselect '\n' from printing
			if(j>maxj)
				maxj=j;
			j=0;

		}
		

		else
		{
		
		
			arr[i][j]=ch;
			j++;
		
		
		}
			
	
	}
//	j--;         //modification 3: 
                     //these 3 lines removed as even last line  contains '\n'
//	if(j>maxj)
///				maxj=j;

	for(int m=0;m<=maxj;m++){
		for(int k=i;k>=0;k--)
			
				printf("%c",arr[k][m]);
		printf("\n");}



	return 0;
}

Posted: Wed Feb 21, 2007 7:24 pm
by mf
Still, your program prints a blank first column. Moreover, it prints \0 instead of some spaces.

Also, why not just let gets() handle all that business with lines and line terminators.
That's so much simpler:

Code: Select all

for (n = 0; gets(arr[n]) != NULL; n++);
// you've read n lines of input into arr[0], ..., arr[n-1]

Posted: Sun Feb 25, 2007 9:24 am
by S.M. Arifuzzaman
I am busy with my exam now, so I m temporarily retired. Anyway thnx mf for his suggestion. I expect to start very soon with his suggestion.

490 PE~~~Help

Posted: Fri Apr 06, 2007 7:00 pm
by lena
#include<stdio.h>
#include<string.h>
char a[100][102];
int n;
int len[100];
char res[120];
int main()
{
// freopen("490.txt","r+",stdin);
// freopen("490_O.txt","w+",stdout);
n = 0;
int i,j;
for(i=0;i<100;i++)
for(j=0;j<102;j++)
a[j]=0;
while(gets(a[n])&& strlen(a[n]) !=0 ){


n++;
}

//intf("%d\n",n);
for(i = 0;i<n;i++)len = strlen(a);
int ml = len[0];
for(i=0;i<n;i++) if(len>ml) ml = len;

for(i=0;i<ml;i++)
{
for(j=n-1;j>=0;j--)
if(a[j] == 0 || a[j] == '\t')
printf(" ");
else
printf("%c",a[j]);

if(i!=ml-1)
printf("\n");
}
//while(true){}
return 0;
}

Posted: Mon Apr 16, 2007 10:27 pm
by Jan
Search your problem first. Don't open a new thread if there is one already.