fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. struct produto {
  7. char nome[20];
  8. float valor;
  9. };
  10. typedef struct produto PRODUTO;
  11.  
  12. struct compras {
  13. char nome[20];
  14. int quantidade;
  15. };
  16. typedef struct compras COMPRAS;
  17.  
  18. int main() {
  19.  
  20. int N, M, P, i, j, k;
  21. PRODUTO p[100];
  22. COMPRAS c[100];
  23.  
  24. scanf ("%d", &N);
  25. for (i=0; i<N; i++) {
  26. scanf ("%d", &N);
  27. for (j=0; j<N; j++) {
  28. scanf ("%s", p[j].nome);
  29. scanf ("%f", &p[j].valor);
  30. }
  31. scanf ("%d", &P);
  32. for (j=0; j<P; j++) {
  33. scanf ("%s", c[j].nome);
  34. scanf ("%d", &c[j].quantidade);
  35. }
  36.  
  37. float total = 0;
  38. for (j=0; j<P; j++) {
  39. for (k=0; k<N; k++) {
  40. if ( strcasecmp( p[k].nome, c[j].nome ) == 0 ) total = total + (p[k].valor * c[j].quantidade);
  41. }
  42.  
  43. }
  44.  
  45. printf ("R$ %.2f\n", total);
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 4732KB
stdin
1
5
uva  2.50
banana 4.00
mamao 2.10
limao 6.00
laranja 5.00
5
uva 10
banana 10
mamao 15
limao 12
laranja 18
stdout
R$ 258.50
R$ 258.50
R$ 258.50
R$ 258.50
R$ 258.50