标签:
1 #include <iostream> 2 #include <stdio.h> 3 #include <cmath> 4 #include <string> 5 #include <algorithm> 6 #include <memory.h> 7 8 using namespace std; 9 10 const double PI = acos(-1.0); 11 const double eps = 1e-6; 12 const double INF = 1e9 + 7; 13 14 15 16 int a[10]; 17 void exchange(int a[], int begin, int end) 18 { 19 int temp; 20 while (begin<end) 21 { 22 temp = a[begin]; 23 a[begin] = a[end]; 24 a[end] = temp; 25 begin++; 26 end--; 27 } 28 29 } 30 31 int main() 32 { 33 freopen("data.in", "r", stdin); 34 35 int m; 36 memset(a, 0, 10); 37 for (int i = 0; i < 10; i++) 38 { 39 cin >> a[i]; 40 } 41 42 cin >> m; 43 exchange(a,0,10-m-1); 44 exchange(a, 10-m, 9); 45 exchange(a, 0,9); 46 47 int beginSum = 0; 48 int endSum = 0; 49 for (int i = 0; i < m; i++) 50 { 51 beginSum += a[i]; 52 53 } 54 55 for (int j = 9; j >10 - m -1; j--) 56 { 57 endSum += a[j]; 58 } 59 60 for (int i = 0; i < 9; i++) 61 { 62 cout << a[i] << " "; 63 } 64 cout <<a[9] << endl; 65 cout << beginSum << " "<< endSum << endl; 66 67 system("pause"); 68 return 0; 69 }
标签:
原文地址:http://www.cnblogs.com/lishichao/p/4847159.html