SHOW:
|
|
- or go back to the newest paste.
1 | include <iostream> | |
2 | #include <math.h> | |
3 | #include <iomanip> | |
4 | ||
5 | ||
6 | using namespace std; | |
7 | ||
8 | int func(int n, int i,int* A, double maxA, int a, int b, float sum,int m, int* B, int j) | |
9 | { | |
10 | ||
11 | ||
12 | ||
13 | ||
14 | ||
15 | for (int i = 0; i < n; i++) { | |
16 | cin >> A[i]; | |
17 | } | |
18 | ||
19 | maxA = -1000; | |
20 | for (int i = 0; i < n; i++) | |
21 | { | |
22 | if (fabs(A[i]) > maxA) | |
23 | { | |
24 | maxA = fabs(A[i]); | |
25 | } | |
26 | ||
27 | } | |
28 | cout << fixed << setprecision(6) << maxA; | |
29 | a = -1; | |
30 | b = -1; | |
31 | for (int i = 0; i < n; i++) { | |
32 | if ((A[i] > 0) && (a == -1)) { | |
33 | a = i; | |
34 | i++; | |
35 | } | |
36 | else if ((A[i] > 0) && (b == -1)) { | |
37 | b = i;}} | |
38 | for (int i = 0; i < n; i++) | |
39 | if ((i > a) && (i < b)) | |
40 | sum += A[i]; | |
41 | cout << fixed << setprecision(6) << " " << sum; | |
42 | for (int j = 0; j < m; j++) { | |
43 | B[j] = 0; | |
44 | } | |
45 | cout << endl; | |
46 | for (int i = 0; i < n; i++) | |
47 | { | |
48 | if ((i >= a) && (i <= b)){ | |
49 | B[j] = A[i]; | |
50 | j++;}} | |
51 | for (int i = 0; i < n; i++){ | |
52 | if ((i < a) || (i > b) && (A[i] != 0)){ | |
53 | B[j] = A[i]; | |
54 | j++;}} | |
55 | for (int i = 0; i < n; i++) { | |
56 | A[i] = B[i];} | |
57 | for (j = 0; j < m; j++) { | |
58 | cout << B[j] << ".00" << " ";} | |
59 | delete[] A; | |
60 | delete[] B; | |
61 | return 1;} | |
62 | int main() { | |
63 | int a=-1, b=-1; | |
64 | int n = 50; | |
65 | int* A = new int[n]; | |
66 | int i = 0; | |
67 | cin >> n; | |
68 | double maxA=-1000; | |
69 | float sum=0; | |
70 | int j = 0; | |
71 | int m = n; | |
72 | int* B = new int[m]; | |
73 | func(n, i, A, maxA, a, b, sum, m, B, j); | |
74 | return 1; | |
75 | system("pause"); | |
76 | } |