Friday 27 July 2018

Cookery Contest
 
Suzanne is participating in the Cookery Contest to be held at her Company. Suzanne is just a beginner in cooking but is more creative. She wanted to give a good show though she is going to cook for the first time. So she decided to cook only a small portion of her recipe, which has the same ratios of ingredients, but makes less food.
 
Suzanne however, does not like fractions. The original recipe contains only whole numbers of ingredients, and Suzanne wants the reduced recipe to only contain whole numbers of ingredients as well. Help her determine how much of each ingredient to use in order to make as little food as possible.

 
Input Format:
The first line of the input consists of a positive integer N, which corresponds to the number of ingredients.
Next line contains N space-separated integers, each indicating the quantity of a particular ingredient that is used.


Output Format:
Output exactly N space-separated integers on a line that gives the quantity of each ingredient that Suzanne should use in order to make as little food as possible.
Refer sample input and output for formatting specifications.


Sample Input 1:
2
4 4


Sample Output 1:
1 1

Sample Input 2:
3
2 3 4


Sample Output 2:
2 3 4


Solution:
#include<stdio.h>
int main()
{
    int n,a[10],i,j,k,g=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    k=a[0];
    for(i=1;i<n;i++)
    {
        if(a[i]<k)
        k=a[i];
    }
    for(i=1;i<=k;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[j]%i!=0)
            {
                break;
            }
        }
        if(j==n)
        g=i;
    }
    for(i=0;i<n;i++)
    {
        printf("%d ",a[i]/g);
    }
    return 0;

}

1 comment:

Random password generator in Java

       Random password generator in Java Source code: mport java.io.*; import java.util.*; public class Main { public static void main(Str...