第十一届蓝桥杯大赛软件类省赛第二场 C&&C++大学 B组

第十一届蓝桥杯大赛软件类省赛第二场 C&&C++大学 B组

试题A:门牌制作

在这里插入图片描述

思路:

1到2020之间的数字少,可直接采用一个循环,然后对里面的每一个数字进行查找

identifying code

#include<iostream>
using namespace std;

int main()
{
	int sum=0;
	
	for(int i=1;i<=2020;i++){
		int x=i,t;
		//对里面的每个数字进行判断
		while(x>0){
			t=x%10;
			x/=10;
			if(t==2)
				sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
 } 

答案:624

试题B:寻找2020

在这里插入图片描述

解题思路

就是采用两个循环进行分子分母的遍历,然后判断分字分母是否是互为质数,是则 ans++;

Identifying code

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int ans=0;
	for(int i=1;i<=2020;i++)
	{
		for(int j=1;j<=2020;j++)
		{
			if(__gcd(i,j)==1)
				ans++;
		}	
	}	
	cout<<ans<<endl;
	return 0;
}

答案:2481215

试题C:蛇形填数

在这里插入图片描述

解题思路

在这里插入图片描述

identifying code

#include<iostream>
using namespace std;

int main()
{
	int s[100][100];
	
	int x=0,y=0;
	int data=1;
	s[x][y]=data++;
	
	while(s[19][19]==0){
		if(x==0){
			y++;//向右 
			s[x][y]=data++;
			while(y!=0){//左下移动 
				x++;
				y--;
				s[x][y]=data++;
			}
		}else if(y==0){
			x++;//垂直向下 
			s[x][y]=data++;
			while(x!=0){ //右上移动 
				x--;
				y++;
				s[x][y]=data++;
			}
		}
	}
	cout<<s[19][19]<<endl;
	return 0; 
}

答案:761

试题D:跑步锻炼

在这里插入图片描述

解题思路

identifying code

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	int start=5;//0星期一,1星期二,2星期三,3星期三,4星期四,5星期六,6星期日 
	int ans=0,m=0,year,day;
	
	year=2000;
	while(year!=2020 || month[m]!=10){
		if(year%400==0 || (year%4==0&&year%100!=0))
			month[2]=29;
		else month[2]=28;
		
		for(m=1;m<=12;m++){
			if(year==2020 && m==10) goto mark;
			int day=month[m]-(7-start); //舍弃初始的一周 
			ans++;
			ans+=day/7; //一个月剩下时间有多少个周一 
			start=day%7;
			if(start!=0) ans++; //这个月剩下的残缺周还有一个星期一 
			ans+=month[m];
		}		
		year++;
	}
	mark:
	ans+=2;
	cout<<ans<<endl;
	return 0;
 } 

答案:8879

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值