예제 #1
0
int largestRectangle(int* height, int n)
{
	int i,j,k;
	int max = -1;
	int auxiliaryArray[1024] = {0};

	for(i=0;i<n;i++)
	{
		// left[i]
		for(j=i;j>=0;j--)
		{
			if(height[j]>=height[i])
			{
				left[i]++;					
			}
			else
				break;
		}
		// right[i]
		for(k=i;k<n;k++)
		{
			if(height[k]>=height[i])
			{
				right[i]++;					
			}
			else
				break;
		}
		printf("the %d'th width is %d\n",i,left[i]+right[i]-1);
		auxiliaryArray[i] = left[i]+right[i]-1;
	}
	max = maxOfArray(auxiliaryArray,n);
	return max;
}
예제 #2
0
void main() {
	float a[6] = {1,2,3,4,5,6};
	float m = maxOfArray(a,6);
	printMatrix(a,1,6);
	printf("%.1f\n\n",m);
	
	float A[2][3] = {{1,2,3},{4,5,6},{7,8,9}};
	printMatrix(A,2,3);
	float maxOfA1[3];
	float maxOfA2[2];
	maxOfMatrix(A,2,3,maxOfA1,1);
	maxOfMatrix(A,2,3,maxOfA2,2);
	printMatrix(maxOfA1,1,3);
	printMatrix(maxOfA2,1,2);
}
예제 #3
0
int main()
{
    int array[SIZE], sizeOfPart, maxElement, minElement;
    printf("Enter the size of array (0 < size <= %d): ", SIZE);
    scanf("%d", &sizeOfPart);
    askForGenerateOrWriting(array, sizeOfPart);
    universalClear();
    printf("Your array:\n");
    outputArrray(array, sizeOfPart);
    maxElement = maxOfArray(array, sizeOfPart);
    minElement = minOfArray(array, sizeOfPart);
    for(int i = 0; i < sizeOfPart; ++i)
    {
        array[i] = array[i] % 2? minElement : maxElement;
    }
    printf("New array:\n");
    outputArrray(array, sizeOfPart);
    return 0;
}