202006-1线性分类器 csp考试题

202006-1线性分类器 csp考试题
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

踩坑点:== 和 equals 的区别没有搞清楚。
0x00 在静态方法中不能创建内部类的实例对象;
0x01 == 比较的是引用,equals比较的是内容;
0x02 Scanner类的一些方法没有弄清楚用法:
next() : 返回一个字符串,将空格当做两个字符串之间的间隔;
nextLine() : 将一整行都当做字符串进行返回,包括空格;
nextInt() :与next()类似,返回的是int类型的值;


```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static class Triplet<A,B,C>{
		private final A a;
		private final B b;
		private final C c;
		public Triplet(A ma, B mb, C mc) {
			a = ma;
			b = mb;
			c = mc;
		}
		public A getA() {
			return a;
		}
		public B getB() {
			return b;
		}
		public C getC() {
			return c;
		}
		
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int pointNum = sc.nextInt();
		//System.out.println(pointNum);
		int queryNum = sc.nextInt();
		int i = 0;
		Integer a;
		Integer b;
		String c;
		List<Triplet<Integer,Integer,String>> t = new ArrayList<>();
//		t.add(new Triplet<Integer,Integer,String>(a,b,c));
//		System.out.println(t.get(0).getC());
//		System.out.println(t.get(0).getB());
//		System.out.println(t.get(0).getA()*t.get(0).getB());
		//向List容器中添加pointNum个点
		while(i < pointNum) {
		     a = sc.nextInt();
		     b = sc.nextInt();
		     c = sc.next();
			 t.add(new Triplet<Integer, Integer, String>(a,b,c));
			i++;
		}
		int j = 0;
		int countA = 0;
		int countB = 0;
		int flagA = 0;
		int flagB = 0;
		for(int k = 0; k < pointNum; k++) {
			//System.out.println(t.get(k).getC());
			//System.out.println(t.get(k).getC().equals("A"));
			if(t.get(k).getC().equals("A") == true) {
				countA++;
			}
			else if(t.get(k).getC().equals("B") == true) {
				countB++;
     		}
		}
		//System.out.println("queryNum:"+queryNum);
		while(j < queryNum) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			int temp3 = sc.nextInt();
			for(int f1 = 0; f1 < pointNum; f1++) {
				if(t.get(f1).getC().equals("A") == true) {
					int flag = temp1 + temp2*t.get(f1).getA() + temp3*t.get(f1).getB();
				
				//System.out.println("flag:"+flag);
					if(flag > 0) {
						flagA++;
					}	
				}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值