07: no maximum number and the same number of

Total time limit: 1000ms memory limit: 65536kB
described
output an integer sequence number is not the same as the maximum sum of the numbers.

Input
Input into two lines:
a first behavior N (N is the number of the next number, N <= 100);
a second behavior of N integers, and the number to a number between separate spaces, each integer is the range -1000,000 to 1000,000.
Output
the output of the maximum number and the remaining digits of the number N is removed.
Sample input
3
. 1 2 3
Sample Output
3

#include<iostream>
using namespace std;
int main(){
	int N;
	cin>>N;
	
	long long a[N+5];
	long long sum=0;
	long long max=-1;
	int count=0;
	//sum表示所有输入数的总和,max表示输入的最大的数,count表示最大的数出现的次数
	for(int i=1;i<=N;i++){
		cin>>a[i];
		if(a[i]>max){
			max=a[i];
			//最大的数第一次出现
			count=1;
		}else if(a[i]==max){
		//最大的数每出现一次,count就自增一
			count++;
		}
		
		
		sum+=a[i];
	}
	
	cout<<(sum-max*count);
	
	return 0;
} 
Published 36 original articles · won praise 0 · Views 343

Guess you like

Origin blog.csdn.net/weixin_44437496/article/details/104043129