Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define mx 110
- int Grid[mx];
- int T, N, M;
- void removeInd(int a[], int ind)
- {
- int i;
- for (i = ind; i < N-1; i++)
- {
- a[i] = a[i + 1];
- }
- N--;
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- int t, i, x, y, j, k;
- int maxVal, totVal, tempMax, maxInd;
- scanf("%d", &T);
- for (t = 1; t <= T; t++)
- {
- totVal = 0;
- scanf("%d", &N);
- M = N;
- for (i = 0; i < N; i++)
- {
- scanf("%d", &Grid[i]);
- }
- for (j = 0; j < M; j++)
- {
- printf("\t j = %d\tN = %d\n", j, N);
- maxVal = -1;
- for (i = 0; i < N; i++)
- {
- /*
- if (0 == i && N > 1)
- {
- tempMax = Grid[1];
- }
- else if (0 == i)
- {
- tempMax = 0;
- }
- else if (N == 2)
- {
- tempMax = Grid[0];
- }*/
- if (N == 1)
- tempMax = 0;
- else if (i == 0)
- tempMax = Grid[1];
- else if (i == N-1)
- {
- printf("LastItem = %d\t tempMax = %d\n ", Grid[i], Grid[N - 2]);
- tempMax = Grid[N - 2];
- }
- else
- {
- tempMax = Grid[i - 1] * Grid[i + 1];
- }
- if (tempMax > maxVal)
- {
- maxVal = tempMax;
- maxInd = i;
- }
- }
- totVal += maxVal;
- removeInd(Grid, maxInd);
- printf("For Round %d\n", i);
- for (k = 0; k < N; k++)
- printf("%d ", Grid[k]);
- printf(" === MaxVal = %d \t Total Value = %d\n", maxVal, totVal);
- }
- printf("%d: %d\n", t, totVal);
- /*for (i = 0; i < N; i++)
- printf("%d ", Grid[i]);
- printf("\n");*/
- }
- }
Add Comment
Please, Sign In to add comment