2018科大讯飞笔试题(二)

本文介绍了一个使用Java编写的程序,该程序通过读取输入数据并应用特定算法来计算一个包含变量数量、特定条件下的数值变化及绝对值计算的数学公式。

代码:

package face;


import java.util.Scanner;

public class Test2 {
//	
//	public static int Money(int [] a) {
//		int [] a1=a;
//		int s=0;
//		for(int a2:a1) {
//			if(a2==0) {
//				s=s+1;			
//			}
//			
//		}
//		return s;
//		
//		
//	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int m,n,k,x,sum,Count=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		m=sc.nextInt();
		x=sc.nextInt();
		k=sc.nextInt();
		int a[] = new int [n];
		for(int i=0;i<n;i++){
			if(sc.nextInt()==0)
				Count++;
		}
		sum=m*(n-Count)+Count*(m-x)-Math.abs(k*(n-2*Count));
		System.out.println(sum);
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值