蓝桥杯刷题2020_2_27

T1

一道模拟题

高精度算阶乘

#include <bits/stdc++.h>
using namespace std;
void f(int n){
	if(n == 1){
		cout << "1";
	}		
	else {
		int a[100000];
		int e = 0, s = 0, p = 0;
		a[0] = 1;
		for(int i = 2; i <= n; ++i){
			for(int j = s; j <= e; ++j){
				p = a[j] * i + p;
				a[j] = p % 10;
				p /= 10;
			}
			while(p != 0){//这部处理十分重要 因为并不知道会进多少位
				e++;
				a[e] = p % 10;
				p /= 10;
			}
		}	
		for(int i = e; i >= 0; --i)
			cout << a[i];
	}
}
int main (){
	int n;
	cin >> n;
	f(n);
	cout << endl;
	return 0;
}

 T2

sb题

复习一下transform函数

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

	int main (){
		string a, b;
		cin >> a >> b;
		string c = a;
		string d = b;
		transform(c.begin(), c.end(), c.begin(), ::toupper);
		transform(d.begin(), d.end(), d.begin(), ::toupper);
		if(a.size() != b.size()){
			cout << 1 << endl;
		}
		else if(a == b) {
			cout << 2 << endl;
		}
		else if(c == d){
			cout << 3 << endl;
		}
		else {
			cout << 4 << endl;
		}
	}

 T3

    //矩形相交问题
#include <bits/stdc++.h>
using namespace std;
int main (){
	//本题由相交矩形的顶点来求解比较简单
	double x1, x2, x3, x4, y1, y2, y3, y4;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
	double x = min(max(x1, x2), max(x3, x4));
	double xx = max(min(x1, x2), min(x3, x4));
	double y = max(min(y1, y2), min(y3, y4));
	double yy = min(max(y1, y2), max(y3, y4));
	if(x > xx && yy > y){
		printf("%.2f\n", (x - xx) * (yy - y));
	}
	else{
		printf("0.00\n");
	}
}

 ..............后面刷的一些题就不往上传了==

猜你喜欢

转载自www.cnblogs.com/lightac/p/12374799.html