Page 9 of 17

Posted: Sun Feb 06, 2005 6:06 pm
by UFP2161
The scanf function requires the cstdio include.

Though, you should really never mix calls between scanf and cin (likewise for printf and cout).

Posted: Sun Feb 06, 2005 6:17 pm
by sklitzz
Aaargh! I hate mistakes like this!

Anyway thanks!

195 problem

Posted: Mon Feb 07, 2005 3:53 pm
by sklitzz
I don't know why I get WA, maybe someone sees the error...

Code: Select all

#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int N;
set < string > perms;
typedef set < string >::iterator SIT;

int main()
{
	cin >> N;
	for( int i = 0; i < N; ++i )
	{
		string t; cin >> t;
		//generate_perms
		sort( t.begin(), t.end() );
		do
		{
			perms.insert( t );
		} while( next_permutation( t.begin(), t.end() ) );
		
		//output_perms
		for( SIT it = perms.begin(); it != perms.end(); ++it  )
			cout << *it << endl;
		perms.clear();
	}
	
	return 0;
}


Posted: Mon Feb 07, 2005 5:03 pm
by GVahe
Hi, maybe this small test case will help u

input
1
Ca
ouput
aC
Ca

Posted: Mon Feb 07, 2005 6:40 pm
by sklitzz
Does this mean that 'C'(big c) should be behind 'a'(small a ) although c is capital?

Posted: Mon Feb 07, 2005 6:52 pm
by GVahe
sklitzz wrote:Does this mean that 'C'(big c) should be behind 'a'(small a ) although c is capital?
of course, but I don't know if there is such function in C++ for this problem. I think u must do it yourself (like me).

Posted: Tue Feb 08, 2005 10:12 pm
by sklitzz
Could anyone tell me why this comparision doesn't work?

Code: Select all

struct cmp
{
	bool operator () ( const string &a, const string &b )
	{
		string s1 = "", s2 = "";
		for( int i = 0; i < a.length(); ++i ) s1 += toupper( a[i] );
		for( int i = 0; i < b.length(); ++i ) s2 += toupper( b[i] );
		
		if( s1 == s2 ) return ( a < b );
		return ( s1 < s2 ); 
	}
};

195 Compile error !!!!!!!!!

Posted: Fri Feb 18, 2005 9:04 am
by ibrahim
I got compile error with this code. Anybody help me? :(

Code: Select all

#include <stdio.h>
#include <string.h>

long double fact[20] ={1,1,2,6,24,120,720,5020,40320,362880,3628800,39916800,479001600,479001600,87178291200,1307674368000,20922789888000};

long int q;

int permutation(char *a,long int n)
{
	long int j,k,r,s,v;
	char temp;
	j = n - 2;
	while (a[j]>=a[j+1])
	{
		j--;
	}
	if (j<0)
	{
		return 1;
	}
	k = n - 1;
	while (a[j]>=a[k])
	{
		k--;
	}
	temp = a[j];
	a[j] = a[k];
	a[k] = temp;
	r = n - 1;
	s = j + 1;
	while (r>=s)
	{
		temp = a[r];
		a[r] = a[s];
		a[s] = temp;
		r--;
		s++;
	}
	printf ("%s\n",a);
	return 1;
}

void sort(char *arr,long int n)
{
	long int i,j;
	char temp;
	for (i=0;i<n-1;i++)
	{
		for (j=0;j<n-1-i;j++)
		{
			if (arr[j]>arr[j+1])
			{
				temp = arr[j+1];
				arr[j+1] = arr[j];
				arr[j] = temp;
			}
		}
	}
}


int main()
{
	char s1[1000];
	long int len,i,kase,j,v,k,flag;
	scanf ("%ld",&kase);

	for (j=0;j<kase;j++)
	{
		scanf ("%s",s1);
		flag = 0;
		len = strlen(s1);
		for (k=0;k<len;k++)
		{
			if (s1[0] == s1[k]);
			else
			{
				flag = 1;
				break;
			}
		}

		if (flag)
		{
			sort(s1,len);
			printf ("%s\n",s1);
			q = 0;
			for (i=0;i<fact[len]-1;i++)
			{
			v = permutation(s1,len);
			if (!v) break;
			}
		}
		else 
			printf ("%s\n",s1);

		//printf ("\n");

	}
return 0;
}






[/quote]

Posted: Fri Feb 18, 2005 9:35 am
by Krzysztof Duleba
You use numbers that don't fit into an integer. You should tell the compiler that in fact they are doubles by adding .0 at the end of each.

Posted: Fri Feb 18, 2005 9:40 am
by ibrahim
Dear Duleba,
But i got accept in 10098 using this code with small change. :(

WA 195 please help

Posted: Fri Feb 18, 2005 7:45 pm
by ibrahim
After solving the compile error i got WA :-? . Please give me some critical input and output from your AC program. :(

Posted: Sat Feb 19, 2005 12:14 pm
by Krzysztof Duleba
Is this C or C++ code? If it's C then you shouldn't use C++-style comments (//).

Posted: Sat Feb 19, 2005 12:46 pm
by ibrahim
Krzysztof Duleba wrote:Is this C or C++ code? If it's C then you shouldn't use C++-style comments (//).
Yes, I got the mistake. but after that i got WA. Can you help me by giveing input output :( .
And what's diferents between 10098 and this. I did not found anything :-? .
Thanks

Posted: Sat Feb 19, 2005 2:46 pm
by Krzysztof Duleba
Input:

Code: Select all

1
bBaA
Output:

Code: Select all

AaBb
AabB
ABab
ABba
AbaB
AbBa
aABb
aAbB
aBAb
aBbA
abAB
abBA
BAab
BAba
BaAb
BabA
BbAa
BbaA
bAaB
bABa
baAB
baBA
bBAa
bBaA

Posted: Tue Feb 22, 2005 3:39 pm
by shamim
input:
AaB
output:
AaB
ABa
aAB
aBA
BAa
BaA