⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sgu405.java

📁 SGU题库第四版前10题的题目解答。前三题是CPP程序
💻 JAVA
字号:
import java.io.*;
import java.util.*;
import java.math.*;

public class Solution implements Runnable {
	Scanner in;
	PrintWriter out;
	int n, m;
	
	private int Estimate(int a, int b, int _a, int _b) {
		int res = 0;
		if (a > b && _a > _b || a == b && _a == _b || a < b && _a < _b) res += 2;
		if (a - b == _a - _b) res += 3;
		if (a == _a) res++;
		if (b == _b) res++;
		return res;
	}
	
	private void Solve() {
		n = in.nextInt();
		m = in.nextInt();
		int score[] = new int[n];
		Arrays.fill(score, 0);
		int i, j, a, b, _a, _b;
		for (i = 0; i < m; i++) {
			a = in.nextInt();
			b = in.nextInt();
			for (j = 0; j < n; j++) {
				_a = in.nextInt();
				_b = in.nextInt();
				score[j] += Estimate(a, b, _a, _b);
			}
		}
		for (i = 0; i < n; i++) {
			if (i > 0) out.print(' ');
			out.print(score[i]);
		}
		out.println();
	}
	
	public void run() {
		try {
			in = new Scanner(new FileReader("input.txt"));
			out = new PrintWriter(System.out);
			while (in.hasNextInt())
				Solve();
			in.close();
			out.close();
		}
		catch (Exception ex) {
			ex.printStackTrace();
			System.exit(-1);
		}
	}
	
	public static void main(String args[]) {
		new Thread(new Solution()).start();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -