0
点赞
收藏
分享

微信扫一扫

【备战蓝桥】 算法·每日一题(详解+多解)-- day2

【备战蓝桥】 算法·每日一题(详解+多解)-- day2

✨博主介绍

第一题

题目描述

#include<bits/stdc++.h>
using namespace std;
int res = 0;

void check(int n){
	while(n){
		int tmp = n % 10;
		if(tmp == 2) res ++;
		n /= 10;
	}
}

int main() {


	for(int i = 1; i <= 2020; i++){
		check(i);
	} 

	cout << res << endl;
	return 0;
}

第二题

题目描述:

#include<bits/stdc++.h>

using namespace std;

int main() {
	int res = 0;

	for(int i = 1; i <= 2020; i++){
		for(int j = 1; j <= 2020; j++){
			if(__gcd(i, j) == 1) res ++;
		}
	}

	cout << res << endl;
	return 0;
}



第三题

题目描述:

#include<bits/stdc++.h>

using namespace std;

int main() {
	int res = 1;

	for(int i = 2; i <= 20; i++){
		res += (i-1) * 4;
	}

	cout << res;
	return 0;
}


第四题

题目描述:

#include<bits/stdc++.h>

using namespace std;

int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool check(int n){
	int year = n / 10000;
	int month = n % 10000 / 100;
	int day = n % 100;

	if(month <= 0 || month > 12) return false;
	if(day <= 0 || months[month] < day && month != 2) return false;

	if(month == 2){
		bool run = year % 4 == 0 && year % 100 || year % 400 == 0;
		if(run + months[2] < day) return false; 
	}

	return true;
}

int main() {
	int res = 0, days = 5;
	for(int i = 20000101; i <= 20201001; i++){
		if(check(i)){

			if(days % 7 == 0 || i % 100 == 1) res += 2;
			else res++;
			days++;
		}
	}

	cout << res << endl;
	return 0;
}



第五题

题目描述:

#include <bits/stdc++.h>

using namespace std;

int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool check(int n) {
	int year = n / 10000;
	int month = n % 10000 / 100;
	int day = n % 100;

	if(month <= 0 || month > 12) return false;
	if(day <= 0 || day > months[month] && month != 2) return false;

	if(month == 2) {
		int run = year % 4 == 0 && year % 100 || year % 400 == 0;
		if(day > run + months[2]) return false;
	}

	return true;
}

int main() {
	int n, c;
	cin >> c;
	while(c --) {
		cin >> n;
		int a = 0, b = 0; //a代表下一个回文日期,b代表 ABABBABA 型的回文日期
		for(int i = 1000; i < 10000; i++) {
			int u = i, v = i;
			for(int i = 0; i < 4; i++) {
				u = u * 10 + v % 10;
				v /= 10;
			}
			int day = u % 100;
			int month = u % 10000 / 100;

			if(check(u) && u > n) {
				if(a == 0) a = u;
				if(b == 0 && day == month && day / 10 != day % 10) b = u;
			}

		}

		cout << a << endl << b << endl;
	}

	return 0;
}

第六题

题目描述:

#include <bits/stdc++.h>

using namespace std;

int main() {
	int n = 0, m = 0, c = 0, l;
	cin >> c;
	l = c;
	while(c --){
		int tmp;
		cin >> tmp;
		if(tmp >= 60) n ++;
		if(tmp >= 85) m ++;
	}

	printf("%.0f%%\n%.0f%%", 100 * (double(n) / l), 100 * (double(m) / l)) ;
	return 0;
}

💫点击直接资料领取💫

这里有各种学习资料还有有有趣好玩的编程项目,更有难寻的各种资源。 ​ ​

❤️关注苏州程序大白公众号❤️

👇 👇👇

举报

相关推荐

0 条评论