sadiqul_amin

baloon

Apr 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #define mx 110
  3.  
  4. int Grid[mx];
  5.  
  6. int T, N, M;
  7.  
  8. void removeInd(int a[], int ind)
  9. {
  10.     int i;
  11.     for (i = ind; i < N-1; i++)
  12.     {
  13.         a[i] = a[i + 1];
  14.     }
  15.     N--;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21.     freopen("input.txt", "r", stdin);
  22.     // freopen("output.txt", "w", stdout);
  23.  
  24.     int t, i, x, y, j, k;
  25.     int maxVal, totVal, tempMax, maxInd;
  26.  
  27.     scanf("%d", &T);
  28.  
  29.     for (t = 1; t <= T; t++)
  30.     {
  31.         totVal = 0;
  32.         scanf("%d", &N);
  33.         M = N;
  34.         for (i = 0; i < N; i++)
  35.         {
  36.             scanf("%d", &Grid[i]);
  37.         }
  38.  
  39.         for (j = 0; j < M; j++)
  40.         {
  41.             printf("\t j = %d\tN = %d\n", j, N);
  42.             maxVal = -1;
  43.             for (i = 0; i < N; i++)
  44.             {
  45.                 /*
  46.                 if (0 == i && N > 1)
  47.                 {
  48.                     tempMax = Grid[1];
  49.                 }
  50.                 else if (0 == i)
  51.                 {
  52.                     tempMax = 0;
  53.                 }
  54.                 else if (N == 2)
  55.                 {
  56.                     tempMax = Grid[0];
  57.                 }*/
  58.                
  59.                 if (N == 1)
  60.                     tempMax = 0;
  61.                 else if (i == 0)
  62.                     tempMax = Grid[1];
  63.                 else if (i == N-1)
  64.                 {
  65.                     printf("LastItem = %d\t tempMax = %d\n ", Grid[i], Grid[N - 2]);
  66.                     tempMax = Grid[N - 2];
  67.                 }
  68.                 else
  69.                 {
  70.                     tempMax = Grid[i - 1] * Grid[i + 1];
  71.                 }
  72.  
  73.                 if (tempMax > maxVal)
  74.                 {
  75.                     maxVal = tempMax;
  76.                     maxInd = i;
  77.                 }
  78.             }
  79.  
  80.             totVal += maxVal;
  81.             removeInd(Grid, maxInd);
  82.  
  83.             printf("For Round %d\n", i);
  84.             for (k = 0; k < N; k++)
  85.                 printf("%d ", Grid[k]);
  86.             printf(" === MaxVal = %d \t Total Value = %d\n", maxVal, totVal);
  87.  
  88.         }
  89.  
  90.    
  91.         printf("%d: %d\n", t, totVal);
  92.  
  93.  
  94.         /*for (i = 0; i < N; i++)
  95.             printf("%d ", Grid[i]);
  96.         printf("\n");*/
  97.     }
  98. }
Add Comment
Please, Sign In to add comment