标签:ios others blog uri 时间 sort stream har acm
5 5 8 13 27 14
# include<iostream> # include<string> # include<stdio.h> # include<algorithm> using namespace std; int main() { int N,i,j,cha; char s[20]; while(1) { cin>>s; if(s[0]==‘E‘ && s[1]==‘O‘ &&s[2]==‘F‘) { break; } N = atoi(s); int a[N]; for(i=0;i<N;i++) { cin>>a[i]; } sort(a,a+N);//从小到大排序 cha = a[N-1] - a[N-2];//得到第一个差 for(i=N-3;i>=0;i--) { if(cha >= a[i]) { cha = cha - a[i]; } else { cha = a[i] - cha; } } cout<<cha<<endl; } return 0; }
第二种做法:
标签:ios others blog uri 时间 sort stream har acm
原文地址:http://www.cnblogs.com/wshyj/p/6363712.html