2015浙江省蓝桥杯c/c++B组个人题解

奖券数目


有些人很迷信数字,比如带“4”的数字,认为和“死”谐音,就觉得不吉利。
虽然这些说法纯属无稽之谈,但有时还要迎合大众的需求。某抽奖活动的奖券号码是5位数(10000-99999),要求其中不要出现带“4”的号码,主办单位请你计算一下,如果任何两张奖券不重号,最多可发出奖券多少张。

52488


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <cstdlib>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main()
 {
 	int i,j,ans=0,p,t,flag;
 	for(i=10000;i<100000;i++)
 	{
 		t=i;
 		flag=0;//??4 
		while(t!=0)
		{
			if(t%10==4)
			{
				flag=1;
				break;
			}				
			t/=10;
		} 
		if(flag==0)
		{
			ans++;
			//cout<<i<<" ";
		}		
	}
	cout<<ans<<endl;
 	system("pause");
	return 0;
}


星系炸弹



在X星系的广袤空间中漂浮着许多X星人造“炸弹”,用来作为宇宙中的路标。
每个炸弹都可以设定多少天之后爆炸。
比如:阿尔法炸弹2015年1月1日放置,定时为15天,则它在2015年1月16日爆炸。
有一个贝塔炸弹,2014年11月9日放置,定时为1000天,请你计算它爆炸的准确日期。


请填写该日期,格式为 yyyy-mm-dd  即4位年份2位月份2位日期。比如:2015-02-19
请严格按照格式书写。不能出现其它文字或符号。

2017-08-05

可惜我算错了- -

三羊献瑞



观察下面的加法算式:


      祥 瑞 生 辉
  +   三 羊 献 瑞
-------------------
   三 羊 生 瑞 气


(如果有对齐问题,可以参看【图1.jpg】)


其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。


请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容。


1085




格子中输出



StringInGrid函数会在一个指定大小的格子中打印指定的字符串。
要求字符串在水平、垂直两个方向上都居中。
如果字符串太长,就截断。
如果不能恰好居中,可以稍稍偏左或者偏上一点。


下面的程序实现这个逻辑,请填写划线部分缺少的代码。


#include <stdio.h>
#include <string.h>


void StringInGrid(int width, int height, const char* s)
{
int i,k;
char buf[1000];
strcpy(buf, s);
if(strlen(s)>width-2) buf[width-2]=0;

printf("+");
for(i=0;i<width-2;i++) printf("-");
printf("+\n");

for(k=1; k<(height-1)/2;k++){
printf("|");
for(i=0;i<width-2;i++) printf(" ");
printf("|\n");
}

printf("|");

printf("%*s%s%*s",_____________________________________________);  //填空
         
printf("|\n");

for(k=(height-1)/2+1; k<height-1; k++){
printf("|");
for(i=0;i<width-2;i++) printf(" ");
printf("|\n");
}

printf("+");
for(i=0;i<width-2;i++) printf("-");
printf("+\n");
}


int main()
{
StringInGrid(20,6,"abcd1234");
return 0;
}


对于题目中数据,应该输出:
+------------------+
|                  |
|     abcd1234     |
|                  |
|                  |
+------------------+




(如果出现对齐问题,参看【图1.jpg】)


注意:只填写缺少的内容,不要书写任何题面已有代码或说明性文字。


buf[width-2]==0?0:(width-2-strlen(s))/2,buf[width-2]==0?"":" ",buf,buf[width-2]==0?0:(width-1-strlen(s))/2,buf[width-2]==0?"":" "




九数组分数



1,2,3...9 这九个数字组成一个分数,其值恰好为1/3,如何组法?


下面的程序实现了该功能,请填写划线部分缺失的代码。


#include <stdio.h>


void test(int x[])
{
int a = x[0]*1000 + x[1]*100 + x[2]*10 + x[3];
int b = x[4]*10000 + x[5]*1000 + x[6]*100 + x[7]*10 + x[8];

if(a*3==b) printf("%d / %d\n", a, b);
}


void f(int x[], int k)
{
int i,t;
if(k>=9){
test(x);
return;
}

for(i=k; i<9; i++){
{t=x[k]; x[k]=x[i]; x[i]=t;}
f(x,k+1);
_____________________________________________ // 填空处
}
}

int main()
{
int x[] = {1,2,3,4,5,6,7,8,9};
f(x,0);
return 0;
}




注意:只填写缺少的内容,不要书写任何题面已有代码或说明性文字。


{t=x[k]; x[k]=x[i]; x[i]=t;}




加法变乘法



我们都知道:1+2+3+ ... + 49 = 1225
现在要求你把其中两个不相邻的加号变成乘号,使得结果为2015


比如:
1+2+3+...+10*11+12+...+27*28+29+...+49 = 2015
就是符合要求的答案。


请你寻找另外一个可能的答案,并把位置靠前的那个乘号左边的数字提交(对于示例,就是提交10)。


注意:需要你提交的是一个整数,不要填写任何多余的内容。




16

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <cstdlib>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int main()
 {
 	int i,j;
 	for(i=1;i<46;i++)
 	{
 		for(j=i+2;j<=49;j++)
 		{
 			int t=i*(i+1)+j*(j+1)-(i*2+2+j*2);
 			if(t==790)
 				cout<<i<<" "<<j<<endl;
 		}
 	}
 	
 	
 	system("pause");
	return 0;
}


牌型种数



小明被劫持到X赌城,被迫与其他3人玩牌。
一副扑克牌(去掉大小王牌,共52张),均匀发给4个人,每个人13张。
这时,小明脑子里突然冒出一个问题:
如果不考虑花色,只考虑点数,也不考虑自己得到的牌的先后顺序,自己手里能拿到的初始牌型组合一共有多少种呢?


请填写该整数,不要填写任何多余的内容或说明文字。
3598180

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <cstdlib>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main()
 {
 	int i[20];
 	long long ans=0;
 	for(i[1]=0;i[1]<=4;i[1]++)
 	for(i[2]=0;i[2]<=4;i[2]++)
 	for(i[3]=0;i[3]<=4;i[3]++)
 	for(i[4]=0;i[4]<=4;i[4]++)
 	for(i[5]=0;i[5]<=4;i[5]++)
 	for(i[6]=0;i[6]<=4;i[6]++)
 	for(i[7]=0;i[7]<=4;i[7]++)
 	for(i[8]=0;i[8]<=4;i[8]++)
 	for(i[9]=0;i[9]<=4;i[9]++)
 	for(i[10]=0;i[10]<=4;i[10]++)
 	for(i[11]=0;i[11]<=4;i[11]++)
 	for(i[12]=0;i[12]<=4;i[12]++)
 	for(i[13]=0;i[13]<=4;i[13]++)
 	{
 		int t=0;
		for(int j=1;j<=13;j++)
			 t+=i[j];
		if(t==13)
			ans++;
	} 
 	cout<<ans<<endl;
 	system("pause");
	return 0;
}




移动距离



X星球居民小区的楼房全是一样的,并且按矩阵样式排列。其楼房的编号为1,2,3...
当排满一行时,从下一行相邻的楼往反方向排号。
比如:当小区排号宽度为6时,开始情形如下:


1  2  3  4  5  6
12 11 10 9  8  7
13 14 15 .....


我们的问题是:已知了两个楼号m和n,需要求出它们之间的最短移动距离(不能斜线方向移动)


输入为3个整数w m n,空格分开,都在1到10000范围内
w为排号宽度,m,n为待计算的楼号。
要求输出一个整数,表示m n 两楼间最短移动距离。


例如:
用户输入:
6 8 2
则,程序应该输出:
4


再例如:
用户输入:
4 7 20
则,程序应该输出:
5


资源约定:
峰值内存消耗 < 256M
CPU消耗  < 1000ms




请严格按要求输出,不要画蛇添足地打印类似:“请您输入...” 的多余内容。


所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。


注意: main函数需要返回0
注意: 只使用ANSI C/ANSI C++ 标准,不要调用依赖于编译环境或操作系统的特殊函数。
注意: 所有依赖的函数必须明确地在源文件中 #include <xxx>, 不能通过工程设置而省略常用头文件。


提交时,注意选择所期望的编译器类型。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <cstdlib>
#include <cmath>
using namespace std;
int map[10005][10005];
int main()
 {
 	int i,j,w,m,n,t,mi,mj,ni,nj;
 	while(cin>>w>>m>>n)
 	{
 		int cnt=1;
 		if(m==n)
 		{
 			cout<<0<<endl;
 			continue;
 		}	
 		else if(m>n)
 			t=m,m=n,n=t;
 		for(i=0;i<100001;i++)
 		{
 			if(i%2)
 			{
 				for(j=w-1;j>=0;j--)
	 			{
	 				map[i][j]=cnt;
	 				if(cnt==m)
	 				{
	 					mi=i;
	 					mj=j;
	 				} 				
	 				if(cnt==n)
	 				{
	 					ni=i;
	 					nj=j;
	 					goto flag;
	 				} 
					cnt++;					
	 			}
 			}
 			else
 			{ 
	 			for(j=0;j<w;j++)
	 			{
	 				map[i][j]=cnt;
	 				if(cnt==m)
	 				{
	 					mi=i;
	 					mj=j;
	 				} 				
	 				if(cnt==n)
	 				{
	 					ni=i;
	 					nj=j;
	 					goto flag;
	 				} 
					cnt++;					
	 			}
	 		} 
 		}
 		flag:cout<<abs(mi-ni)+abs(mj-nj)<<endl; 		
 	}
	return 0;
}


最后两题么没有全写。


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值