Exemple #1
0
int main(void)
// Takes a series of scores from judges and displays all scores,
// the highest score, the lowest score, and the average score.
{
#define scores_size 6
    int scores[scores_size] = {0};
    double score;
    int usable_total;
    double avg;

    for (int i = 0; i < scores_size; i++)
    {
        printf("\nPlease input the score from judge #%d: ", i + 1);
        scanf("%lf", &score);
        score = (int)rint(score*adjust);
        scores[i] = score;
    }
    // Return all scores
    printf("The gymnast's scores are ");
    printArray(scores, scores_size);

    // Sort scores and output high and low values
    sortArray(scores, scores_size);
    printf("The high score is %.1f\n", (double)largest(scores, scores_size) / adjust);
    printf("The low score is %.1f\n", (double)smallest(scores, scores_size) / adjust);

    // Calculate and output average score without high/low values
    usable_total = sum(scores, scores_size);
    usable_total -= largest(scores, scores_size);
    usable_total -= smallest(scores, scores_size);
    avg = average(usable_total, (scores_size - 2));
    printf("The score for this event is %.2f\n", avg / adjust);
}
Exemple #2
0
int smallest(TreeNode* node , int & k)
{
	if (!node) return - 1;
	int val = smallest(node -> left, k);
	if (!k) return val;
	if (!--k) return node->val;
	return smallest(node -> right, k);
}
	multiset<int> smallest(TreeNode* root) {
		multiset<int> res;
		if (root==NULL) return res;
		multiset<int> l=smallest(root->left);
		l.insert(root->val);
		multiset<int> r=smallest(root->right);
		r.insert(root->val);
		if (compare(l, r)<0) return l;
		else return r;
	}
Exemple #4
0
int main()
{
  float F_N=0, U_b=0;
  int cur_time=0,T_1=0,n,i,e;
  printf("\nEnter number of servers\n");
  scanf("%d",&n);
  enterdetails(servers,n);
  printf("\n\n The largest stop time is %d\n",greatest(servers,n));
  while(cur_time<=greatest(servers,n))
    {  
      for(i=0;i<n;i++)
	{
	  if(cur_time==servers[i].start_time && cur_time==smallest(servers,n))
	    {
	      T_1=cur_time;
	      U_b+=servers[i].u;
	      servers[i].fn=servers[i].exec_time/servers[i].u;
	    }
	  if(cur_time!=smallest(servers,n)&&cur_time==servers[i].start_time)
	    {
	      F_N+=(cur_time-T_1)/U_b;
	      T_1=cur_time;
	      U_b+=servers[i].u;
	      servers[i].fn=F_N+servers[i].exec_time/servers[i].u;
	    }
	}
      //disp(servers,n);
      fnsorting(servers,n);
      printf("\nTime\t\tServer\t\tfn\t\tF_N\t\tU_b\n");
      for(i=0;i<n;i++)
	{
	  if(servers[i].fn!=0&&servers[i].stop_time>cur_time)
	    {
	      e=servers[i].exec_time;
	      printf("%d\t\t%s\t\t%0.2f\t\t%0.2f\t\t%0.2f\n",cur_time,servers[i].s_name,servers[i].fn,F_N,U_b);
	      if(cur_time<servers[i].stop_time)
		{
		  servers[i].fn+=servers[i].exec_time/servers[i].u;
		}
	      else
		{
		  F_N+=(cur_time-T_1)/U_b;
		  T_1=cur_time;
		  U_b+=servers[i].u;
		}
	      break;
	    }
	}
  //disp(servers,n);
      cur_time+=e;
    }
}
 bool isValidBST(TreeNode *root) {
     // Note: The Solution object is instantiated only once and is reused by each test case.
     
     if(root == NULL)
     {
         return true;
     }
     int valT = root->val;
     if(root->left != NULL)
     {
         if(biggest(root->left) >= valT)
         {
             return false;
         }
         if(!isValidBST(root->left))
         {
             return false;
         }
     }
     if(root->right != NULL)
     {
         if(smallest(root->right) <= valT)
         {
             return false;
         }
         if(!isValidBST(root->right))
         {
             return false;
         }
     }
    
     return true;
     
 }
Exemple #6
0
//-----------------------------------------------------------------------------
// Purpose: If COPY_ALL_CHARACTERS == max_chars_to_copy then we try to add the whole pSrc to the end of pDest, otherwise
//  we copy only as many characters as are specified in max_chars_to_copy (or the # of characters in pSrc if thats's less).
// Input  : *pDest - destination buffer
//			*pSrc - string to append
//			destBufferSize - sizeof the buffer pointed to by pDest
//			max_chars_to_copy - COPY_ALL_CHARACTERS in pSrc or max # to copy
// Output : char * the copied buffer
//-----------------------------------------------------------------------------
char *V_strncat(char *pDest, const char *pSrc, size_t destBufferSize, int max_chars_to_copy )
{
	size_t charstocopy = (size_t)0;

	mxASSERT( destBufferSize >= 0 );
	AssertValidStringPtr( pDest);
	AssertValidStringPtr( pSrc );

	size_t len = strlen(pDest);
	size_t srclen = strlen( pSrc );
	if ( max_chars_to_copy <= COPY_ALL_CHARACTERS )
	{
		charstocopy = srclen;
	}
	else
	{
		charstocopy = (size_t)smallest( max_chars_to_copy, (int)srclen );
	}

	if ( len + charstocopy >= destBufferSize )
	{
		charstocopy = destBufferSize - len - 1;
	}

	if ( !charstocopy )
	{
		return pDest;
	}

	char *pOut = strncat( pDest, pSrc, charstocopy );
	pOut[destBufferSize-1] = 0;
	return pOut;
}
int main()
{
	struct clinkedlist* last;
	last = NULL;
	int choice;
	int value;
	int p, s, l, d;
	while(1) {
		printf("Choices:\n");
		printf("1. Insert at beginning\n");
		printf("2. Print all the nodes\n");
		printf("3. Print Smallest\n");
		printf("4. Print largest\n");
		printf("5. Print largest - smallest\n");
		printf("6. Exit\n");
		printf("Enter your choice:\n");
		scanf("%d", &choice); 
		
		switch(choice)
		{
			case 1:
				printf("Enter value to be inserted:\n");
				scanf("%d", &value);
				last = insert_beg(last,value);
				break ;
			case 2:
				print_all(last);
				break ;
			case 3:
				s = smallest(last);
				if (s != 0) {
					printf("%d\n", s);
					break;
				}
				printf("List is Empty!!\n");
				break;
			case 4:
				l = largest(last);
				if (l != 0) {
					printf("%d\n", l);
					break;
				}
				printf("List is Empty!!\n");
				break;
			case 5:
				d = difference(last);
				if (d != 0) {
					printf("%d\n", d);
					break;
				}
				printf("List is Empty!!\n");
				break;
			case 6:
				exit(1);
			default:
				printf("Invalid Choice!\n");		
		}
	}
	return 0;
}
Exemple #8
0
unsigned
computeRecursive(unsigned n)
{
	if (!n)
	{
		return 0;
	}

	//IntVector candidates = getNext(n);
	if (n >= 25)
	{
		return 1 + smallest(computeRecursive(n - 1), computeRecursive(n - 10), computeRecursive(n - 25));
	}
	
	if (n >= 10)
	{
		return 1 + std::min(computeRecursive(n - 1), computeRecursive(n - 10));
	}
	
	if (n >= 1)
	{
		return 1 + computeRecursive(n - 1);
	}
	
	return n;
}
int main(void)
{
    Ttime j;
    Ttime time[M];
    Ttime dur;
    Ttime smal;
    int i = 0;

    printf("How many times you have? ");
    scanf("%d", &j);

    for(i = 0; i<j; i++) {
        printf("Give the time %d (hh mm)? ", i+1);
        read_time(&time[i]);
    }

    smal = smallest(time, j);
    //printf("%d" , smal);
    //display_time(&smal);
    printf("Result list:\n");
    for(i = 0; i<j; i++) {
        time_diff(&smal, &time[i], &dur);
        display_time(&time[i]);
        printf(" ");
        display_time(&dur);
        printf("\n");
    }

    return 0;
}
Exemple #10
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *in - 
//			*out - 
//			outSize - 
//-----------------------------------------------------------------------------
void V_StripExtension( const char *in, char *out, int outSize )
{
	// Find the last dot. If it's followed by a dot or a slash, then it's part of a 
	// directory specifier like ../../somedir/./blah.

	// scan backward for '.'
	int end = V_strlen( in ) - 1;
	while ( end > 0 && in[end] != '.' && !PATHSEPARATOR( in[end] ) )
	{
		--end;
	}

	if (end > 0 && !PATHSEPARATOR( in[end] ) && end < outSize)
	{
		int nChars = smallest( end, outSize-1 );
		if ( out != in )
		{
			memcpy( out, in, nChars );
		}
		out[nChars] = 0;
	}
	else
	{
		// nothing found
		if ( out != in )
		{
			V_strncpy( out, in, outSize );
		}
	}
}
int difference(struct clinkedlist* last)
{
	int s, l, d;
	s = smallest(last);
	l = largest(last);
	d = l - s;
	return d;
}
Exemple #12
0
void	resolve(t_tetri *tab, t_var *var, int nbtetri)
{
	char			square[26][27];

	initab(square);
	smallest(nbtetri, var);
	chgsmall(square, 0, var);
	parsingv3(square, tab, nbtetri, var);
}
Exemple #13
0
void selection(){
    int i; 
    printf("Sorted \n");
    for(i =0; i < n; ++i)
    {
        b[i] = smallest();
        printf("%d\t", b[i]);
    }
}
Exemple #14
0
//-----------------------------------------------------------------------------
// Purpose: Extracts the base name of a file (no path, no extension, assumes '/' or '\' as path separator)
// Input  : *in - 
//			*out - 
//			maxlen - 
//-----------------------------------------------------------------------------
void V_FileBase( const char *in, char *out, int maxlen )
{
	mxASSERT( maxlen >= 1 );
	mxASSERT( in );
	mxASSERT( out );

	if ( !in || !in[ 0 ] )
	{
		*out = 0;
		return;
	}

	int len, start, end;

	len = V_strlen( in );

	// scan backward for '.'
	end = len - 1;
	while ( end&& in[end] != '.' && !PATHSEPARATOR( in[end] ) )
	{
		end--;
	}

	if ( in[end] != '.' )		// no '.', copy to end
	{
		end = len-1;
	}
	else 
	{
		end--;					// Found ',', copy to left of '.'
	}

	// Scan backward for '/'
	start = len-1;
	while ( start >= 0 && !PATHSEPARATOR( in[start] ) )
	{
		start--;
	}

	if ( start < 0 || !PATHSEPARATOR( in[start] ) )
	{
		start = 0;
	}
	else 
	{
		start++;
	}

	// Length of new sting
	len = end - start + 1;

	int maxcopy = smallest( len + 1, maxlen );

	// Copy partial string
	V_strncpy( out, &in[start], maxcopy );
}
Exemple #15
0
/*
 * Helper function to push element down a heap.
 */
void push_down(double heap[], unsigned int n,  unsigned int i)
{
	unsigned int smallesti = smallest(heap,n,i);
	if( smallesti != i ){
		double temp = heap[smallesti];
		heap[smallesti] = heap[i];
		heap[i] = temp;
		push_down(heap, n, smallesti);
	}
}
int main(int argc, char** argv)
{
    
    int a = atoi(argv[1]);
    int b = atoi(argv[2]);
    int c = atoi(argv[3]);
    int output = smallest(a, b, c);
    printf("return:%d\n", output);
    return 1;
}
Exemple #17
0
    // Siftdown() finds the children of the node given, compares
    // their values and swaps them if necessary. It then recurses
    // on the swapped child since the swap could have upset the
    // heap property on lower subtrees.
    void siftDown(int *node){
        // base case
        if(isLeaf(node)) return;

        int *left = leftChildOf(node), *right = rightChildOf(node);
        int *min_child = smallest(left,right);
        if(*node > *min_child) swapValues(min_child, node);

        // recursion
        siftDown(min_child);
    }
Exemple #18
0
void main(){
	//Do not change this function
	char word1[100], word2[100], word3[100];

	printf("Enter the first word: ");
	gets(word1);

	printf("Enter the second word: ");
	gets(word2);

	printf("Enter the third word: ");
	gets(word3);

	smallest(word1, word2);
	smallest(word1, word3);
	smallest(word2, word3);	
	printf("%s\n%s\n%s\n", word1, word2, word3);

	system("\nPause");
}
Exemple #19
0
void printTree(Node* root) {
	char* prefix = "";

	Node* p = smallest(root);

	while (p) {
		printf("%s%d", prefix, p->value);
		prefix = ", ";
		p = successor(p);
	}
	printf("\n");
}
Exemple #20
0
char* AllocString( const char *pStr, int nMaxChars )
{
	int allocLen;
	if ( nMaxChars == -1 )
		allocLen = strlen( pStr ) + 1;
	else
		allocLen = smallest( (int)strlen(pStr), nMaxChars ) + 1;

	char *pOut = new char[allocLen];
	V_strncpy( pOut, pStr, allocLen );
	return pOut;
}
Exemple #21
0
/*	==================== selectSort ====================
	Sorts by selecting smallest element in unsorted portion 
	of the array and exchanging it with element at the 
	beginning of the unsorted list.
	   Pre   array must contain at least one item 
	         pLast is pointer to last element in array
	   Post  array rearranged smallest to largest
*/
void selectSort (int *pAry, 
                 int *pLast)
{
/*	Local Definitions */
	int *pWalker; 
	int *pSmallest; 

/*	Statements */
	for (pWalker = pAry; pWalker < pLast; pWalker++) 
	    {
	     pSmallest = smallest (pWalker, pLast);
	     exchange (pWalker, pSmallest);
	    } /* for */
	return;
}	/* selectSort */
Exemple #22
0
Fichier : Ex7-3.c Projet : ragmha/C
int main()
{
    int max,min,num1, num2, num3;
    printf("Enter the 1. number:");
    scanf("%d", &num1);
    printf("Enter the 2. number:");
    scanf("%d", &num2);
    printf("Enter the 3. number:");
    scanf("%d", &num3);

    max = largest(num1, num2, num3);
    min = smallest(num1, num2, num3);

    printf("Among the numbers you entered,\nthe largest was %d and the smallest was %d.",max,min);


    return 0;
}
int prediction(char name[])
{
    //Uses first algorithm to predict the value of required bitmap
    int n,i;
    float dist[10];
    dist[0]=distancesq1(name,"data/ave0.txt");
    dist[1]=distancesq1(name,"data/ave1.txt");
    dist[2]=distancesq1(name,"data/ave2.txt");
    dist[3]=distancesq1(name,"data/ave3.txt");
    dist[4]=distancesq1(name,"data/ave4.txt");
    dist[5]=distancesq1(name,"data/ave5.txt");
    dist[6]=distancesq1(name,"data/ave6.txt");
    dist[7]=distancesq1(name,"data/ave7.txt");
    dist[8]=distancesq1(name,"data/ave8.txt");
    dist[9]=distancesq1(name,"data/ave9.txt");
    n=smallest(dist);
    return n;
}
Exemple #24
0
static void PackVertexAttribI( const int* _srcPtr, UINT _srcDimension,
					   void *_dstPtr, AttributeTypeT _dstType, UINT _dstDimension )
{
	const UINT minCommonDim = smallest(_srcDimension, _dstDimension);
	//const UINT leftOver = _dstDimension - minCommonDim;
	switch( _dstType )
	{
	case AttributeType::Byte :
	case AttributeType::UByte :
		{
			UINT8* dstPtr8 = (UINT8*)_dstPtr;
			switch(minCommonDim)
			{
			default:	*dstPtr8++ = (UINT8)( *_srcPtr++ );
			case 3:		*dstPtr8++ = (UINT8)( *_srcPtr++ );
			case 2:		*dstPtr8++ = (UINT8)( *_srcPtr++ );
			case 1:		*dstPtr8++ = (UINT8)( *_srcPtr++ );
			}
		}
		break;

	case AttributeType::Short :
		UNDONE;
	case AttributeType::UShort :
		UNDONE;
	case AttributeType::Half :
		UNDONE;
	case AttributeType::Float :
		{
			float* dstPtrF = (float*)_dstPtr;
			switch(minCommonDim)
			{
			default:	*dstPtrF++ = (float)( *_srcPtr++ );
			case 3:		*dstPtrF++ = (float)( *_srcPtr++ );
			case 2:		*dstPtrF++ = (float)( *_srcPtr++ );
			case 1:		*dstPtrF++ = (float)( *_srcPtr++ );
			}
		}
		break;
	mxNO_SWITCH_DEFAULT;
	}
}
Exemple #25
0
void doDijkstra(int ** m, int n, int s) {
    int Q[n], p[n], d[n], v, u, alt;
    initDijkstra(Q, p, d, n, s);
    int i = n;
    while(i--) {  // O(|V|)
        u = smallest(Q, d, n);  // melhor caso O(1) e pior O(|V|)
        for(v = 0; v < n; v++) {
            if(Q[v] != -1 && u != v && m[u][v] != -1) {
                alt = d[u] + m[u][v];
                if(alt < d[v]) {
                    d[v] = alt;
                    p[v] = u;
                }
            }
        }
    }

    for(v = 0; v < n; v++) {
        printf("No: %d, Relaxamento:%d, No anterior:%d\n", v, d[v], p[v]);
    }
}
Exemple #26
0
unsigned int treeNodes(Node* root) {
    if (!root) { return 0; }
    int nodes = 1;
    root = smallest(root);
    while ((root = successor(root))) {
        ++nodes;
    }
    return nodes;
    /* Marginally better performance in a balenced tree.
    if (root == nullptr) { return 0; }
    int nodes = 1;
    Node* curr = root;
    while ((curr = nextNode(curr)) != nullptr) {
        ++nodes;
    }
    curr = root;
    while ((curr = prevNode(curr)) != nullptr) {
        ++nodes;
    }
    return nodes;
    */
}
Exemple #27
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *in - 
//			numchars - 
//			*out - 
//			maxoutputbytes - 
//-----------------------------------------------------------------------------
void V_hextobinary( char const *in, int numchars, BYTE *out, int maxoutputbytes )
{
	int len = V_strlen( in );
	numchars = smallest( len, numchars );
	// Make sure it's even
	numchars = ( numchars ) & ~0x1;

	// Must be an even # of input characters (two chars per output BYTE)
	mxASSERT( numchars >= 2 );

	memset( out, 0x00, maxoutputbytes );

	BYTE *p;
	int i;

	p = out;
	for ( i = 0; 
		( i < numchars ) && ( ( p - out ) < maxoutputbytes ); 
		i+=2, p++ )
	{
		*p = ( V_nibble( in[i] ) << 4 ) | V_nibble( in[i+1] );		
	}
}
Exemple #28
0
void dj(int start)
{
      int i,j,small=start-1;
           T.dist[start-1]=0;
      for(;;)
      {      
             printf("hi");
             T.known[small]=1;
             displaytable();
             for(j=0;j<G.n;j++)
             {
                               if(T.known[j]==0 && G.matrix[small][j]!=0)
                                    if(T.dist[small] + G.matrix[small][j] < T.dist[j])
                                    {
                                                     T.pv[j]=small+1;
                                                     T.dist[j]=T.dist[small] + G.matrix[small][j];
                                    }
             }
             small=smallest();
             if(small==-1)
                 break;                       
      }
}               
Exemple #29
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *path - 
//			*dest - 
//			destSize - 
// Output : void V_ExtractFilePath
//-----------------------------------------------------------------------------
bool V_ExtractFilePath (const char *path, char *dest, int destSize )
{
	mxASSERT( destSize >= 1 );
	if ( destSize < 1 )
	{
		return false;
	}

	// Last char
	int len = V_strlen(path);
	const char *src = path + (len ? len-1 : 0);

	// back up until a \ or the start
	while ( src != path && !PATHSEPARATOR( *(src-1) ) )
	{
		src--;
	}

	int copysize = smallest( src - path, destSize - 1 );
	memcpy( dest, path, copysize );
	dest[copysize] = 0;

	return copysize != 0 ? true : false;
}
Exemple #30
0
constant_exprt unsignedbv_typet::smallest_expr() const
{
  return to_constant_expr(from_integer(smallest(), *this));
}