2022.7.27 LeetCode AcWing

LeetCode

模拟 + 字符串
题解如下:
https://leetcode.cn/problems/fraction-addition-and-subtraction/solution/by-sen-xm-u2ak/

string转int:
https://blog.csdn.net/xiong452980729/article/details/61677701
int转string:
to_string() 头文件为 #include

AcWing

模拟

#include <bits/stdc++.h>
using namespace std;

const int N = 5e3 + 10;

int w[N];

int main() {
	int T;
	cin >> T;
	for (int ct = 1; ct <= T; ct++) {
		memset(w, 0, sizeof w);
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++) {
			int a, b;
			cin >> a >> b;
			for (int i = a; i <= b; i++)
				w[i]++;
		}
		int p;
		cin >> p;
		cout << "Case #" << ct << ":";
		for (int i = 1; i <= p; i++) {
			int q;
			cin >> q;
			cout << " " << w[q];
		}
		cout << endl;
	}

	return 0;
}
posted @ 2022-07-27 10:00  superPG  阅读(24)  评论(0编辑  收藏  举报