PAT L2-017 人以群分(25 分)
2018-08-04 00:30
253 查看
STL sort排序+判断的水题
[code]//排序 PAT L2-017 #include <iostream> #include <algorithm> using namespace std; int a[100005]; int main(void) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } sort(a,a+n); if(n%2==0)//如果是偶数 { int totalf = 0; int totals = 0; for(int i=0;i<n/2;i++) { totalf += a[i]; } for(int i=n/2;i<n;i++) { totals += a[i]; } printf("Outgoing #: %d\n",n/2); printf("Introverted #: %d\n",n/2); printf("Diff = %d\n",totals-totalf); } else { int totalf1 = 0; int totals1 = 0; for(int i=0;i<n/2;i++) { totalf1 += a[i]; } for(int i=n/2;i<n;i++) { totals1 += a[i]; } int temp1 = totals1-totalf1; int totalf2 = 0; int totals2 = 0; for(int i=0;i<n/2+1;i++) { totalf2 += a[i]; } for(int i=n/2+1;i<n;i++) { totals2 += a[i]; } int temp2 = totals2-totalf2; // printf("temp1 = %d\ntemp2 = %d\n",temp1,temp2); // system("pause"); if(temp1>temp2) { printf("Outgoing #: %d\n",n/2+1); printf("Introverted #: %d\n",n/2); printf("Diff = %d\n",temp1); } else { printf("Outgoing #: %d\n",n/2); printf("Introverted #: %d\n",n/2+1); printf("Diff = %d\n",temp2); } } }
阅读更多
相关文章推荐
- PAT 天梯赛 L2-017. 人以群分 【排序】
- PAT(天梯赛练习题) -L2-017. 人以群分
- PAT L2-017. 人以群分
- PAT-练习集-L2-017. 人以群分
- PAT - 天梯赛 L2-017 人以群分
- L2-017. 人以群分
- L2-017. 人以群分
- L2-017. 人以群分
- L2-017. 人以群分
- L2-017. 人以群分
- (pat)L2-1. 人以群分
- L2-017. 人以群分
- L2-017. 人以群分(模拟题)
- L2-017. 人以群分
- L2-017. 人以群分
- L2-017. 人以群分
- (vector)L2-017. 人以群分
- PAT L2-008. 最长对称子串(25) (暴力,Manacher算法和DP解决)
- L2-017. 人以群分
- L2-017. 人以群分(2017初赛)