UVA – 628 – Password

Problem Link : UVA – 628 – Password


#include <stdio.h>
using namespace std;
int R, W, combination[10];
char word[105][305], rule[1005][305];
void generate(int r, int w, int index, int length) {
	if (index == length) {
		for (int c = 0, i = 0; rule[r][i]; i++) {
			if (rule[r][i] == '0')
				printf("%c", '0' + combination[c++]);
			else
				printf("%s", word[w]);
		}
		putchar('\n');
	} else
		for (int i = 0; i < 10; i++) {
			combination[index] = i;
			generate(r, w, index + 1, length);
		}
}
int main() {
	while (scanf("%d", &W) != EOF) {
		for (int i = 0; i < W; i++)
			scanf("%s", word[i]);
		scanf("%d", &R);
		for (int i = 0; i < R; i++) {
			scanf("%s", rule[i]);
			int height = 0;
			for (int j = 0; rule[i][j]; j++)
				height += (rule[i][j] == '0');
			printf("--\n");
			for (int j = 0; j < W; j++)
				generate(i, j, 0, height);
		}
	}
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: