Cod sursa(job #439440)

Utilizator maria.eniEni Maria-Adina maria.eni Data 11 aprilie 2010 16:12:50
Problema Gutui Scor 0
Compilator c Status done
Runda teme_upb Marime 1.43 kb

//#include <stdlib.h>
#include <stdio.h>


int main()
{

	int h[100], g[100];
	int i, j, n, hmax, up, count, put, aux, sum=0;
	
	FILE* fin;
	FILE* fout;
	
	fin = fopen ("gutui.in", "r");
	fout = fopen ("gutui.out", "w");
	
	fscanf (fin, "%d %d %d", &n, &hmax, &up);
	printf("%d %d %d", n, hmax, up);

	for ( i=0; i<n; i++)
		fscanf ( fin, "%d %d", &h[i], &g[i] );
	
	int up1=up;
	count=0;
	while ( up1 / 10)
	{
		up1 = up1 / 10;
		count= count +1;
	}

	put=1;
	while( count)
	{
		put = put * 10;
		count = count - 1 ;
	}
	
	for( i=0; i<n; i++)
		for( j=i+1; j<n; j++)
	{
		if ( (h[i] / put) < (h[j] / put) )
		{
			aux = h[i];
			h[i] = h[j];
			h[j] = aux;
			
			aux = g[i];
			g[i] = g[j];
			g[j] = aux;
		}
		
	}
	
	for( i=0; i<n-1;i++)
    {
         for ( j=i+1; j<n;j++)
             if( (h[i] / put) == (h[j] / put) )
             {
                        while( g[i] < g[j] )
                        {
                        aux = h[i];
						h[i] = h[j];
						h[j] = aux;
			
						aux = g[i];
						g[i] = g[j];
						g[j] = aux;
						}
             }
    }
    
    for( i=0; i<n-1; i++)
    {
    	if( h[i] <= hmax)
    	{
    		sum = sum + g[i];
    		for( j=i+1; j<n; j++)
    			h[j] = h[j] + up;
    		
		}

    	
	}
	fprintf(fout, "%d ", sum);
	fprintf(fout, "\n");
	
	for( i=0; i<n; i++)
		fprintf(fout, "%d ", h[i]);
		
	fprintf(fout, "\n");	
	for( i=0; i<n; i++)
		fprintf(fout, "%d ", g[i]);
	
	fclose(fin);
	fclose(fout);

return 0;
}