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++;
}
}