标签:链接 bsp == href tar problem ++ 代码 span
#include<stdio.h> int main() { int a[1001]; int i,j,t,n; while(scanf("%d",&n) != EOF){ for(i = 0; i < n; i++){ scanf("%d",&a[i]); } //冒泡排序(升序) for(i = 0 ;i < n - 1;i ++){ for(j = 0;j < n- i -1;j ++){ if(a[j] > a[j + 1]){ t = a[j]; a[j] = a[j + 1]; a[j + 1] = t; } } } int ans = 0; //答案 for(i = 0 ;i < n - 2;i ++){ int l = a[i] + a[i + 1] + a[i + 2]; //周长 //如果可以构成三角形,则更新最大周长 if(a[i] + a[i + 1] > a[i + 2] && ans < l){ ans = l; } } if(ans == 0) printf("-1\n"); else printf("%d\n",ans); } return 0; }
标签:链接 bsp == href tar problem ++ 代码 span
原文地址:https://www.cnblogs.com/huhusw/p/9465543.html