Advertisement
Guest User

3.3

a guest
Apr 8th, 2020
222
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.  
  3. int a[10101], b[10101], c[10101], d[10101];
  4. int ans[10101], ansi[10101], check=0, count=0;
  5.  
  6. void change(int, int);
  7. void counting(int, int);
  8.  
  9. int main()
  10. {
  11.     int n=0, N=0, i, j, k;
  12.     char e, f;
  13.  
  14.     while(~scanf("%d%c%d%c", &a[n], &e, &b[n], &f))
  15.     {
  16.         n++;
  17.  
  18.         if((e=='\n') || (f=='\n') || (f=='\r'))   break;
  19.     }
  20.  
  21.     while(~scanf("%d%c%d%c", &c[N], &e, &d[N], &f))
  22.     {
  23.         N++;
  24.  
  25.         if((e=='\n') || (f=='\n') || (f=='\r'))   break;
  26.     }
  27.  
  28.     for(i=0; i<n; i++)
  29.         for(j=0; j<N; j++)
  30.         {
  31.             for(k=count-1; k>=0; k--)
  32.             {
  33.                 if(b[i]+d[j]==ansi[k])
  34.                 {
  35.                     ans[k] += a[i] * c[j];
  36.                     check = 1;
  37.  
  38.                     break;
  39.                 }
  40.             }
  41.  
  42.             if(check==0)
  43.             {
  44.                 counting(i, j);
  45.  
  46.                 count++;
  47.             }
  48.  
  49.             check = 0;
  50.         }
  51.  
  52.     for(i=0; i<count-1; i++)
  53.         for(j=0; j<count-1-i; j++)
  54.             if(ansi[j]<ansi[j+1])
  55.                 change(j, j+1);
  56.  
  57.     for(i=0; i<count; i++)
  58.         printf("%d %d ", ans[i], ansi[i]);
  59.  
  60.     return 0;
  61. }
  62.  
  63. void counting(int x, int y)
  64. {
  65.     ans[count] = a[x] * c[y];
  66.     ansi[count] = b[x] + d[y];
  67. }
  68.  
  69. void change(int count, int y)
  70. {
  71.     check = ansi[count];
  72.     ansi[count] = ansi[y];
  73.     ansi[y] = check;
  74.  
  75.     check = ans[count];
  76.     ans[count] = ans[y];
  77.     ans[y] = check;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement