Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int a[10101], b[10101], c[10101], d[10101];
- int ans[10101], ansi[10101], check=0, count=0;
- void change(int, int);
- void counting(int, int);
- int main()
- {
- int n=0, N=0, i, j, k;
- char e, f;
- while(~scanf("%d%c%d%c", &a[n], &e, &b[n], &f))
- {
- n++;
- if((e=='\n') || (f=='\n') || (f=='\r')) break;
- }
- while(~scanf("%d%c%d%c", &c[N], &e, &d[N], &f))
- {
- N++;
- if((e=='\n') || (f=='\n') || (f=='\r')) break;
- }
- for(i=0; i<n; i++)
- for(j=0; j<N; j++)
- {
- for(k=count-1; k>=0; k--)
- {
- if(b[i]+d[j]==ansi[k])
- {
- ans[k] += a[i] * c[j];
- check = 1;
- break;
- }
- }
- if(check==0)
- {
- counting(i, j);
- count++;
- }
- check = 0;
- }
- for(i=0; i<count-1; i++)
- for(j=0; j<count-1-i; j++)
- if(ansi[j]<ansi[j+1])
- change(j, j+1);
- for(i=0; i<count; i++)
- printf("%d %d ", ans[i], ansi[i]);
- return 0;
- }
- void counting(int x, int y)
- {
- ans[count] = a[x] * c[y];
- ansi[count] = b[x] + d[y];
- }
- void change(int count, int y)
- {
- check = ansi[count];
- ansi[count] = ansi[y];
- ansi[y] = check;
- check = ans[count];
- ans[count] = ans[y];
- ans[y] = check;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement