10776 - Determine The Combination

All about problems in Volume 107. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10776 - Determine The combination

Post by brianfry713 » Mon Jun 04, 2012 10:56 pm

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
Check input and AC output for thousands of problems on uDebug!

mathgirl
New poster
Posts: 36
Joined: Tue Apr 24, 2012 6:20 pm

Re: 10776 - Determine The combination

Post by mathgirl » Tue Jun 05, 2012 12:56 pm

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10776 - Determine The combination

Post by brianfry713 » Tue Jun 05, 2012 10:46 pm

Random input:
mdtbezqgzvfowjie 13

The first line of the output is:
bdeefgijmoqtv
Check input and AC output for thousands of problems on uDebug!

Mukit Chowdhury
Learning poster
Posts: 98
Joined: Fri Aug 17, 2012 9:23 pm
Location: Dhaka
Contact:

Re: 10776 - Determine The combination

Post by Mukit Chowdhury » Mon Oct 08, 2012 12:48 pm

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....... :)
Last edited by Mukit Chowdhury on Sat Nov 03, 2012 6:43 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10776 - Determine The combination

Post by brianfry713 » Mon Oct 08, 2012 9:13 pm

On my UNIX machine using g++, for input:mdtbezqgzvfowjie 13
The first line of your output is:
bdeefgijoqvwz
AC output is:
bdeefgijmoqtv
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 107 (10700-10799)”