35 7 50 Sample Output6 SourceThe 6th UESTC Programming Contest Recommendlcy | We have carefully selected several similar problems for you: 2537 2534 3787 2531 2529Statistic | Submit | Discuss | Note #include<stdio.h>#include<iostream>#include<algorithm>using namespace std;int a[150]= {0};int main(){ int n; while(cin>>n&&n) { int k,t; for(int i=1; i<=n; i++) scanf("%d",&a[i]); for(int i=1; i<n; i++) { k=i; for(int j=i; j<=n; j++) { if(a[k]>a[j]) k=j; } t=a[k]; a[k]=a[i]; a[i]=t; } //sort(a,a+n); int sum=0; for(int i=1; i<=n/2+1; i++) { sum=a[i]/2+1 + sum; } printf("%d/n",sum); } return 0;}当然 也可以用sort排序代替选择排序:
#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;int a[150]= {0};int main(){ int n; while(cin>>n&&n) { int k,t; for(int i=0; i<n; i++) scanf("%d",&a[i]); /*for(int i=1; i<n; i++) { k=i; for(int j=i; j<=n; j++) { if(a[k]>a[j]) k=j; } t=a[k]; a[k]=a[i]; a[i]=t; }*/ sort(a,a+n); int sum=0; for(int i=0; i<n/2+1; i++) { sum=a[i]/2+1 + sum; } printf("%d/n",sum); } return 0;}
新闻热点
疑难解答