Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int i,j,k;
- int type,m;
- printf("Enter Num rice type : ");scanf("%d",&type);
- int p[type],q[type];
- float price[100000]={0},temp;
- for(i=0;i<type;i++)
- {
- scanf("%d %d",&p[i],&q[i]);
- price[i]=(float)p[i]/q[i];
- }
- printf("Before Swap\n");
- for(i=0;i<type;i++)
- {
- printf("Price %d = %f\n",i+1,price[i]);
- }
- for(k=1;k<=type;k++)
- {
- for(j=0;j<type-1;j++)
- {
- if(price[j]>price[j+1])
- {
- temp = price[j];
- price[j] = price[j+1];
- price[j+1] = temp;
- temp = q[j];
- q[j] = q[j+1];
- q[j+1] = temp;
- temp = p[j];
- p[j] = p[j+1];
- p[j+1] = temp;
- }
- }
- }
- printf("After Swap\n");
- for(i=0;i<type;i++)
- {
- printf("Price %d = %f\n",i+1,price[i]);
- }
- printf("Enter Merchant number : ");scanf("%d",&m);
- int b[m];
- float sum[100000]={0};
- for(i=0;i<m;i++)
- {
- scanf("%d",&b[i]);
- }
- for(i=0;i<m;i++)
- {
- for(j=0;j<type;j++)
- {
- while(q[j]>0 && b[i]>0)
- {
- sum[i]=sum[i]+price[j];
- q[j]--;
- b[i]--;
- }
- }
- }
- for(i=0;i<m;i++)
- {
- printf("Merchant %d pay = %f\n",i+1,sum[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement