Advertisement
Guest User

1030

a guest
Mar 5th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int i,j,k;
  5.     int type,m;
  6.     printf("Enter Num rice type : ");scanf("%d",&type);
  7.     int p[type],q[type];
  8.     float price[100000]={0},temp;
  9.     for(i=0;i<type;i++)
  10.     {
  11.         scanf("%d %d",&p[i],&q[i]);
  12.         price[i]=(float)p[i]/q[i];
  13.     }
  14.     printf("Before Swap\n");
  15.     for(i=0;i<type;i++)
  16.     {
  17.         printf("Price %d = %f\n",i+1,price[i]);
  18.     }
  19.     for(k=1;k<=type;k++)
  20.     {
  21.         for(j=0;j<type-1;j++)
  22.         {
  23.             if(price[j]>price[j+1])
  24.             {
  25.                 temp = price[j];
  26.                 price[j] = price[j+1];
  27.                 price[j+1] = temp;
  28.                 temp = q[j];
  29.                 q[j] = q[j+1];
  30.                 q[j+1] = temp;
  31.                 temp = p[j];
  32.                 p[j] = p[j+1];
  33.                 p[j+1] = temp;
  34.             }
  35.         }
  36.     }
  37.     printf("After Swap\n");
  38.     for(i=0;i<type;i++)
  39.     {
  40.         printf("Price %d = %f\n",i+1,price[i]);
  41.     }
  42.     printf("Enter Merchant number : ");scanf("%d",&m);
  43.     int b[m];
  44.     float sum[100000]={0};
  45.     for(i=0;i<m;i++)
  46.     {
  47.         scanf("%d",&b[i]);
  48.     }
  49.     for(i=0;i<m;i++)
  50.     {
  51.         for(j=0;j<type;j++)
  52.         {
  53.             while(q[j]>0 && b[i]>0)
  54.             {
  55.                 sum[i]=sum[i]+price[j];
  56.                 q[j]--;
  57.                 b[i]--;
  58.             }
  59.         }
  60.     }
  61.     for(i=0;i<m;i++)
  62.     {
  63.         printf("Merchant %d pay = %f\n",i+1,sum[i]);
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement