1113:不与最大数相同的数字之和
【题目描述】
输出一个整数数列中不与最大数相同的数字之和。
【输入】
输入分为两行:
第一行为N(N为接下来数的个数,N ≤ 100);
第二行N个整数,数与数之间以一个空格分开,每个整数的范围是-1000,000到1000,000。
【输出】
输出为N个数中除去最大数其余数字之和。
【输入样例】
3
1 2 3
【输出样例】
3
代码
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x,max,time,sum=0;
cin>>n;
cin>>x; max=x;time=1; sum+=x;
for(int i=1;i<n;i++){
cin>>x;
sum+=x;
if(x>max) { max=x;time=1;}
else if(x==max) time++;
}
cout<<sum-max*time;
return 0;
}