Jump to content

Rezolvare Subiect 3 Admitere Licenta Informatica Ubb Cluj 2014


Recommended Posts

  • Moderators
Posted

Subiectul se află aici http://www.cs.ubbcluj.ro/wp-content/uploads/subiect-admitere-2014-iulie-informatica.pdf :)

 

Rezolvarea am făcut-o când mă plictiseam la ora de religie :))

#include <iostream>

using namespace std;

void sortare_desc ( unsigned int v[], unsigned int numar_elemente )
{
    for ( unsigned int i = 1 ; i < numar_elemente ; i++ )
    {
        for ( unsigned int j = i + 1 ; j <= numar_elemente ; j++ )
        {
            if ( v[i] < v[j] )
            {
                int aux = v[i];
                v[i] = v[j];
                v[j] = aux;
            }
        }
    }
}


/**
 * Subprogramul punctul a ( generarea primelor nr_elemente elemente din sirul X )
 */
void generare_sir ( unsigned int X[], unsigned int numar_elemente)
{
    unsigned int indice = 0;
    for ( unsigned int i = 1 ; indice <= numar_elemente ; i++ )
    {
        X[ ++indice ] = i;
        for ( unsigned int d = 2 ; d <= i / 2 && indice <= numar_elemente ; d++ )
        {
            if ( i % d == 0 )
            {
                X[ ++indice ] = d;
            }
        }
    }
}



/**
 * Subprogram punctul b ( returnarea primei cifre a unui numar natural )
 */
unsigned int prima_cifra ( unsigned int numar )
{
    while ( numar > 9 )
    {
        numar /= 10;
    }
    return numar;
}



/**
 * Subprogram punctul c ( returnarea ultimei cifre a unui numar natural )
 */
unsigned int ultima_cifra ( unsigned int numar )
{
    return numar % 10;
}



/**
 * Subprogram punctul d ( returnarea cifre maxime a unui numar natural )
 */
unsigned int cifra_maxima ( unsigned int numar )
{
    unsigned int cifra_maxima = 0;
    while ( numar > 0 )
    {
        if ( numar % 10 > cifra_maxima )
        {
            cifra_maxima = numar % 10;
        }
        numar /= 10;
    }
    return cifra_maxima;
}



/**
 * Subprogram punctul e ( construirea matricii A )
 */

void construire_matrice ( unsigned int A[][11], unsigned int n, unsigned int X[] )
{
    for ( unsigned int i = 1 ; i <= n ; i++ )
    {
        for ( unsigned int j = 1 ; j <= n ; j++ )
        {
            if ( i + j == n + 1 )
            {
                A[i][j] = cifra_maxima ( X[ n*n + i*i ] );
            }
            else
            {
                A[i][j] = ( i + j <= n ) ? ultima_cifra( X[ n*n + i + j ] ) : prima_cifra( X[ n*n + i + j ] );
            }
        }
    }
}



/**
 * Subprogramul punctul f
 */
unsigned int generare_numar ( unsigned int A[][11], unsigned int n, unsigned int indice_coloana )
{
    unsigned int v[n+1], numar = 0, i;
    for ( i = 1 ; i <= n ; i++ )
    {
        v[i] = A[i][indice_coloana];
    }

    sortare_desc(v, n);

    for ( i = 1 ; i <= n ; i++ )
    {
        numar = numar * 10 + v[i];
    }
    return numar;
}



int main ( void )
{
    unsigned int n;

    cin >> n;

    unsigned int X[200] = {0}, A[11][11];

    generare_sir( X, 2 * n * n );

    construire_matrice( A, n, X );

    for ( unsigned int j = 1 ; j <= n ; j++ )
    {
        cout << generare_numar( A, n, j ) << ' ';
    }
    return 0;
}

Posted

Problema rezolvata foarte bine , ca de obicei. :))

 

Pentru cine vrea sa faca altfel si sa scrie mai putin poate sa inlocuiasca:

                int aux = v[i];
                v[i] = v[j];
                v[j] = aux;

cu asta : (se foloseste algorithm)

swap(v[i] ,v[j] );

Dar oricum , rezolvarea lui Courage e standard :D

  • Upvote 1

b_350_20_323957_202743_F19A15_111111.png

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.