个人博客:doubleq.win
时间限制: 1 s
空间限制: 1000 KB
题目等级 : 青铜 Bronze
题目描述 Description
输入一列整数,输出它们的总和、最大值、最小值、并从大到小输出。
输入描述 Input Description
第1行:一个整数N表示总共有几个整数要处理
第2行:N个整数
输出描述 Output Description
第1行:它们的总和
第2行:最大值
第3行:最小值
第3+1行:最大值(此行开始从大到小依次输出:注有相同的数字时只输出其中一个)
第3+2行:
........
最后一行:最小值
样例输入 Sample Input
样1:
6
2 5 5 4 9 4
样2:
4
7 7 7 7
样例输出 Sample Output
样1:
29(//提示:这是总和,)
9(//这是最大的数)
2(//这是最小的数)
9
5
4
2
样2:
28
7
7
7
数据范围及提示 Data Size & Hint
从大到小排序输出时,应注意筛除相同的数字(如果系列中全部数均相同,只需要输出其中一个即可)
1 #include<iostream>
2 using namespace std;
3 int a[10001];
4 int tot;//和
5 int maxn=-1;
6 int minn=10000;
7 int b[10001];
8 int main()
9 {
10 int n;
11 cin>>n;
12 for(int i=1;i<=n;i++)
13 {
14 cin>>a[i];
15 tot=tot+a[i];
16 if(a[i]>maxn)
17 maxn=a[i];
18 if(a[i]<minn)
19 minn=a[i];
20 b[a[i]]++;
21 }
22 cout<<tot<<endl;
23 cout<<maxn<<endl;
24 cout<<minn<<endl;
25 for(int i=maxn;i>=0;i--)
26 {
27 if(b[i]!=0)
28 cout<<i<<endl;
29 }
30 return 0;
31 }