Page 2 of 2

Re: 10776 - Determine The combination

Posted: Mon Jun 04, 2012 10:56 pm
by brianfry713
http://www.uvatoolkit.com/problemssolve.php
Output:

Code: Select all

AB
Aa
Ab
Ba
Bb
ab
ABa
ABb
Aab
Bab
BCD
BCE
BCa
BDE
BDa
BEa
CDE
CDa
CEa
DEa
aa
aa
ab
bb
BB
Ba
aa

Re: 10776 - Determine The combination

Posted: Tue Jun 05, 2012 12:56 pm
by mathgirl
Not sure why I m getting WA for this. My output matches with the UVA toolkit. Any tricky inputs?

Code: Select all

#include<iostream>
#include<stdio.h>
#include<string>
#include<set>
#include<algorithm>

using namespace std;

set<string> getcombo(string input,int r)
{
	int n = input.length();
	set<string> combinations;

	for(int i = 0;i <= (n-r);i++)
	{
		string temp = input.substr(i,r);
		for(int j = 0;j < n;j++)
		{
			if(j >= i && j < i + r)
				continue;
			for(int k = 0;k < r;k++)
			{
				string copy(temp);
				char c = input[j];
				copy[k] = c;
				sort(copy.begin(),copy.end());
				combinations.insert(copy);
			}
		}
		sort(temp.begin(),temp.end());
		combinations.insert(temp);
	}

	return combinations;
}

int main()
{
	string input;
	int r;
	while(cin >> input >> r)
	{
		set<string> output = getcombo(input,r);
		set<string>::const_iterator iter;
		for(iter = output.begin();iter != output.end(); iter++)
		{
			cout << *iter << "\n";
		}
	}

	return 0;
}

Re: 10776 - Determine The combination

Posted: Tue Jun 05, 2012 10:46 pm
by brianfry713
Random input:
mdtbezqgzvfowjie 13

The first line of the output is:
bdeefgijmoqtv

Re: 10776 - Determine The combination

Posted: Mon Oct 08, 2012 12:48 pm
by Mukit Chowdhury
Getting WA !!! But can't understand where is the bug !!! please help me giving some inputs for my code......

Code: Select all

Accepted......... :)
Thanks Brianfry713....... :)

Re: 10776 - Determine The combination

Posted: Mon Oct 08, 2012 9:13 pm
by brianfry713
On my UNIX machine using g++, for input:mdtbezqgzvfowjie 13
The first line of your output is:
bdeefgijoqvwz
AC output is:
bdeefgijmoqtv