Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1.  
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6.  
  7. int main()
  8. {
  9. unsigned int i,subseqn=0;
  10. int size;
  11. int b;
  12. long long int *ptr,v;
  13. long long int *numero;
  14.  
  15. char s;
  16. //condicao que le
  17. scanf("%d",&size);
  18. ptr=(long long int*)malloc(size*sizeof(long long int));
  19. for(int i=0;i<size;i++) {
  20. scanf("%lld",&ptr[i]);
  21. }
  22. numero=(long long int*)malloc(size*sizeof(long long int));
  23. char caract[40];
  24. int t;
  25. while(1) {
  26. long long int soma=0;
  27. if(getchar()!=EOF) {
  28. scanf("%c %d",&s,&b);
  29. caract[t]=s;
  30. v=ptr[0];
  31. for(i=0;i<2*size;i++) {
  32. if(s=='m' && ptr[i]<v)
  33. v=ptr[i];
  34. else if(s=='M' && ptr[i]>v)
  35. v=ptr[i];
  36.  
  37. subseqn++;
  38.  
  39. if(subseqn==b || i ==size -1) {
  40. soma+=v;
  41. v=ptr[i+1];
  42. subseqn=0;
  43. }
  44. }
  45. numero[t]=soma;
  46. t++;
  47.  
  48.  
  49. }
  50. else
  51. break;
  52. }
  53.  
  54. for(int i=0;i<t-1;i++) {
  55. if(caract[i]=='m') {
  56.  
  57. printf("+ min %lld\n",numero[i]);
  58. }
  59. else if(caract[i]=='M')
  60. printf("+ max %lld\n",numero[i]);
  61. }
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement