第十届蓝桥杯大赛个人赛省赛(软件类)个人答案

第十届蓝桥杯大赛个人答案

  • 显示八位小数点
  • 修改数组
  • 第2019个质数是多少? = 17551
  • 含有 2、0、1、9 四个数字的立方和 ---243445935333

显示八位小数点

#include <stdio.h>

long long Recursive (long long N){
	if(1 == N || 2 == N)
		return 1;
	else
		return Recursive(N-1) + Recursive(N-2);
}
 
int main(void)
{
	long long N;
	double i,j;
	scanf("%lld",&N);
	i = Recursive(N);
	j = Recursive(N+1);
	printf("%.8lf\n",i/j);
	return 0;
}

修改数组

#include <stdio.h>
//数组遍历 
void ArrTraverse(int * arr,int length){
	int i;
	for(i = 0; i < length; i++){
		printf("%d\t",arr[i]);
	}
	printf("\n",arr[i]);
}
//冒泡排序 
void ArrSort(int * arr,int N){
	int i,j,tmp;
	for(i = 0; i < N; i++){
		for(j = 0; j < N-i-1; j++){
			if(arr[j] > arr[j+1]){
				tmp      = arr[j];
				arr[j]   = arr[j+1];
				arr[j+1] = tmp;
			}
		}
	}
}
//修改数组 
void ArrModify(int * arr,int N){
	int i,j;
	for(i = 0; i < N; i++){
		for(j = 0; j < N-i-1; j++){
			if(arr[j] == arr[j+1]){
				arr[j+1]++;
			}
		}
	}
}
int main(void)
{
	int i,N;
	scanf("%d",&N);
	int arr[N];
	for(i = 0; i < N; i++){
		scanf("%d",&arr[i]);//接收数组 
	} 	
	for(i = 0;i < N; i++){//修改数组 
		ArrModify(arr,N);
		ArrSort(arr,N);	
	}
	ArrTraverse(arr,N);//遍历出来 
	
	return 0;
}

第2019个质数是多少? = 17551

#include <stdio.h>

bool Is_Prime(int x){
	int i;
	if(2 == x)
		return true;
	else{
		for(i = 2; i < x; i++ ){
			if(0 == x%i )
				return false;
			else{
					if(i == x-1)
						return true;
					else
						continue;
				}
		}
	}
}
 
int main(void)
{
	int i=2,count=0,N;
	while(1){	
			if(Is_Prime(i)){
				count++;
				if(2019 == count){
					printf("%d\n",i);
					break;
				}
			}
			i++;	
		}
	return 0;
}

含有 2、0、1、9 四个数字的立方和 —243445935333

#include <stdio.h>

int main(void)
{
	long long result1 = 0;
	long long result2 = 0;
	long long result3 = 0;
	long long result4 = 0;
	long long Final_Result = 0;
	//一位数 
	result1 = 1 + 2*2*2 + 9*9*9;
	int i,a,b,c,d;
	//两位数 
	for(i = 10 ; i < 100;i++){
		a = i/10;
		b = i%10;
		if (2 == a || 0 == a || 1 == a || 9 == a || 
			2 == b || 0 == b || 1 == b || 9 == b){
				result2 = result2 + i*i*i;
			}
	}
	//三位数
	for(i = 100 ; i < 1000;i++){
		a = i/100;
		b = i/10%10;
		c = i%100;
		if (2 == a || 0 == a || 1 == a || 9 == a || 
			2 == b || 0 == b || 1 == b || 9 == b || 
			2 == c || 0 == c || 1 == c || 9 == c){
				result3 = result3 + i*i*i;
			}
	} 
	//四位数
	for(i = 1000 ; i <= 2019;i++){
		a = i/1000;
		b = i/100%10;
		c = i/10%10;
		d = i%10; 
		if (2 == a || 0 == a || 1 == a || 9 == a || 
			2 == b || 0 == b || 1 == b || 9 == b || 
			2 == c || 0 == c || 1 == c || 9 == c ||
			2 == d || 0 == d || 1 == d || 9 == d ){
				result4 = result4 + i*i*i;
			}
	} 
	//最终结果
	Final_Result = result1 + result2 + result3 + result4;
	printf("%lld\n",Final_Result); 
	return  0;	
} 

本人写的都是比较简单的,大神勿喷,谢谢!后期会继续添加答案。

你可能感兴趣的:(记录)