## 10776 - Determine The Combination

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

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

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

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: 99
Joined: Fri Aug 17, 2012 9:23 pm
Location: Dhaka
Contact:

### Re: 10776 - Determine The combination

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

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!