-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCODECHEF_RECIPE.c
70 lines (69 loc) · 884 Bytes
/
CODECHEF_RECIPE.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//CODECHEF Problem : Cutting Recipes (Beginner)
//Problem Code : RECIPE
//Author : By PIYUSH
#include<stdio.h>
#include<stdlib.h>
void display(int *,int,int);
int main()
{
int t,*ptr,*p,no,i,l,j;
scanf("%d",&t);
for(j=1;j<=t;j++)
{
scanf("%d",&no);
if(j==1)
{
ptr = (int *)malloc(no*sizeof(int));
}
else
{
ptr = (int *)realloc(ptr,no*sizeof(int));
}
p=ptr;
for(i=1;i<=no;i++)
{
scanf("%d",ptr);
if(i==1)
{
l=*ptr;
}
if(i>1)
{
if(*ptr<l)
l=*ptr;
}
ptr++;
}
display(p,l,no);
//free(ptr);
}
return 0;
}
void display(int *p,int l,int no)
{
int count=0,i;
int *q;
q=p;
for(i=1;i<=no;i++)
{
if(*p % l == 0)
count++;
p++;
}
if(count == no)
{
for(i=1;i<=no;i++)
{
printf("%d ",*q/l);
q++;
}
}
else
{
for(i=1;i<=no;i++)
{
printf("%d ",*q);
q++;
}
}
}