蓝桥杯——计算机研究生机试真题训练(2017.2.12)

1. (2002 THU)有多少不同的面值组合?


源代码:

#include <stdio.h>
#define maxn 250
int Judge(int a[],int t)
{
	int i,flag=1;
	for(i=0;i<t;i++)
	{
		if(a[i]==a[t])
		{
			flag=0;
			break;
		}
	}
	return flag;
}
int main()
{
	int i,j,k,t=0;
	int a[maxn]={0},count=0;
	for(i=0;i<=5;i++)
	{
		for(j=0;j<=4;j++)
		{
			for(k=0;k<=6;k++)
			{
				a[t]=i*8+j*10+k*18;
				//printf("%d %d %d %d\n",i,j,k,a[t]);
				if(Judge(a,t))
					count++;
				t++;
			}
		}
	}
	printf("%d\n",count-1);
	return 0;
}
程序截图:


2. (2003 THU)今年的第几天?


源代码:

#include <stdio.h>
struct Date
{
	int year;
	int month;
	int day;	
};
void Cal(int year,int month,int day)
{
	int sum=0;
	int t=month-1;
	while(t)
	{
		switch(t)
		{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:sum+=31;break;
			case 4:
			case 6:
			case 9:
			case 11:sum+=30;break;
			case 2:
			{
				if((year%4==0 && year%100!=0) || (year%400==0))
					sum+=29;
				else
					sum+=28;
				break;
			}
		}
		t--;
	}
	sum+=day;
	printf("%d\n",sum);
}
int main()
{
	struct Date d;
	while(scanf("%d",&d.year)!=EOF)
	{
		scanf("%d %d",&d.month,&d.day);
		Cal(d.year,d.month,d.day);
	}
	return 0;
}
程序截图:


3. (2010 SJTU)后缀子串排序


源代码:

#include <stdio.h>
#include <string.h>
#define maxn 1000
struct String
{
	char ch[maxn];
	int len;
} strs[maxn];
int main()
{
	char source[maxn];
	int i,j,Len,num;
	struct String t;
	while(gets(source)!=NULL)
	{
		num=0;
		for(i=0;i<strlen(source);i++)
		{
			Len=0;
			for(j=i;j<strlen(source);j++)
				strs[num].ch[Len++]=source[j];
			strs[num].ch[Len]='\0';
			strs[num].len=Len;
			num++;
		}
		for(i=0;i<num-1;i++)
		{
			for(j=0;j<num-1-i;j++)
			{
				if(strcmp(strs[j].ch,strs[j+1].ch)>0)
				{
					t=strs[j];
					strs[j]=strs[j+1];
					strs[j+1]=t;
				}
			}
		}
		for(i=0;i<num;i++)
		{
			for(j=0;j<strs[i].len;j++)
			{
				printf("%c",strs[i].ch[j]);
				strs[i].ch[j]='\0';
			}
			printf("\n");
		}
	}
	return 0;
}
程序截图:


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值