YTU 1020: I think it
来源:互联网 发布:澳大利亚it 编辑:程序博客网 时间:2024/05/22 09:52
1020: I think it
时间限制: 1 Sec 内存限制: 32 MB提交: 501 解决: 63
题目描述
Xiao Ming is only seven years old, Now I give him some numbers, and ask him what is the second largest sum if he can choose a part of them. For example, if I give him 1 、 2 、 3 , then he should tell me 5 as 6 is the largest and 5 is the second. I think it is too hard for him, isn ’ t it?
输入
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <=10) which is the number of test cases. And it will be followed by T consecutive test cases.
Each test case starts with a line containing an integer N (1<N<10) , the number I give Xiao Ming . The second line contains N Integer numbers ai (-10<ai<10),
输出
For each test case, output the answer.
样例输入
231 2 340 1 2 3
样例输出
55
#include<stdio.h>int jisuan(int a[],int n){ int s,ma,i,j,k,b; s=ma=a[0]; for(i=0; i<n; i++) for(j=i; j<n; j++) { b=0; for(k=i; k<=j; k++)b+=a[k]; if(b>ma)ma=b; } for(i=0; i<n; i++) for(j=i; j<n; j++) { b=0; for(k=i; k<=j; k++)b+=a[k]; if(b>s&&b<ma)s=b; } return s;}int main(){ int N,n,a[15],i,t,j; scanf("%d",&N); while(N--) { scanf("%d",&n); 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; } printf("%d\n",jisuan(a,n)); } return 0;}
总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。
1 0
- YTU 1020: I think it
- 1020 I think it
- I think it
- I think it
- it's hard more than i think
- I think she is an angel, I believe it!
- something about c++ development what i think about it.
- Think about it
- think it over
- think it over
- Setting VirtualBox to use it's built-in VNC server (ver. >= 4.2 I think) - failed
- I think I am wrong
- YTU---2892-I免费看电影
- YTU 2892: I--免费看电影
- 好好想想Think it over
- Think it over……
- delegate and event i think
- I think 'catch that cow'
- Skype for Business 2015新功能之Web会议安排
- 160多个android开源代码汇总
- Object-C 切换到 Swift 全程直播
- 教程网站收集
- java-常用工具命令
- YTU 1020: I think it
- 如何用Maven创建web项目(具体步骤)
- [NOIP2010]关押罪犯
- 近期的烦恼和计划
- 应用评分
- Angular 从0到1 (一) 初识AngularJS
- 在oc项目中添加swift文件,并设置oc-swift混编
- Fragment创建(一)
- HighCharts 详细使用及API文档说明