Cod sursa(job #936769)

Utilizator frostwareDumitrascu Constantin frostware Data 8 aprilie 2013 17:03:45
Problema NKPerm Scor 0
Compilator cpp Status done
Runda Lista lui wefgef Marime 1.26 kb
/*
Name:	Dumitrascu Constantin
Source:	nkperm.cpp
Date:	08 april 2013
*/

#include <fstream>
#include <vector>
#include <algorithm>
//#include <iostream>
using namespace::std;

#define NMAX	1001

#define read_file	"nkperm.in"
#define print_file	"nkperm.out"

int main() {

    int n, k, t, i, j, to, nr_perm = 0;
    char ch;

    vector < vector <int> > vec;
    vector <int> v;


	ifstream get( read_file );
	ofstream put( print_file );

	get >> n >> k >> t;

    for( i = 1; i <= k; i++ )
        for( j = 1; j <= n; j++ )
            v.push_back( j );

    do {
        ++nr_perm;
        vec.push_back( v );
    } while( next_permutation( v.begin(), v.end() ) );


    v.clear();

    to = n * k;

    for( i = 1; i <= t; i++ ) {

        get >> ch;

        if( ch == 'A' ) {

            for( j = 1; j <= to; j++ ) get >> n, v.push_back( n );

            for( size_t it = 0; it != nr_perm; it++ )
                if( vec[it] == v ) put << it << '\n', it = nr_perm-1;


        } else { // ch == 'B'

            get >> n;

            for( size_t it = 0; it != to; it++ )
                put << vec[n-1][it] << ' ';

            put << '\n';

        }

    }

	get.close();
	put.close();

	return 0;
}