Question Set for Re-examination

Keywords: Programming

  1. In his Suanjing, Zhang Qiujian, an ancient Chinese mathematician, put forward a famous problem of "buying a hundred chickens for a hundred bucks".
    Chicken Weng 1, worth five, hen mother 1, worth three, chicken chick 3, worth one hundred to buy a hundred chickens, ask Weng, mother, chick each geometry?
#include "stdio.h"

void main(){
	int i,j,k;
	int sum=100;
	for(i=0;i<=100;i++){
		for(j=0;j<=100;j++){
			for(k=0;k<=100;k++){
				if((i+j+k==100)&&k%3==0){
					if((i*5+j*3+k/3)==sum)
					printf("%d,%d,%d\n",i,j,k);
				}
			}
		}
	}
}
  1. If a fisherman starts fishing every three days from January 1, 2011 and dries his net twice a day,
    Programming to achieve when the input after January 1, 2011 any day, the output of the fisherman is fishing or drying nets.
# include "stdio.h"

void main() {
	int year=2011,month=1,day=1;
	int y=2011,mt=1,d=4;
//	scanf("%d,%d,%d",&y,&mt,&d);
	int i,sum=0,flag,temp;
	int m[12]= {31,28,31,30,31,30,31,31,30,31,30,31};
	if(y>2011) {
		for(i=2012; i<y; i++) {
			flag=0;
			if((y%4==0&&y%100!=0)||y%400==0)	flag=1;
			sum=sum+365+flag;
		}
		sum=sum-1;
		for(i=1; i<mt; i++) {
			if(i==2)	sum=sum+m[i]+flag;
			else sum=sum+m[i];
		}
		sum=sum+d;
		temp=sum%5;
		if(temp>3)	printf("Screen mesh!");
		else printf("Fishing!");

	} else {
		for(i=1; i<mt; i++) {
			sum=sum+m[i];
		}
		sum=sum-1+d;
		temp=sum%5;
		if(temp>3)	printf("Screen mesh!");
		else printf("Fishing!");
	}

}
  1. Suppose that a pair of rabbits mature in one month, that is, one month can grow into rabbits.
    So, if each pair of rabbits gives birth to a pair of rabbits every month, a pair of newborn rabbits will begin to give birth to rabbits from the second month.
    How many pairs of rabbits will there be every month after breeding from a pair of rabbits?
#include "stdio.h"
void main(){
	int a=1,b=1,m,i,temp;
	scanf("%d",&m);
	if(m==1||m==2)	printf("1");
	else{
		for(i=3;i<=m;i++){
			temp=a;
			a=b;
			b=b+temp;
		}
		printf("%d",b);
	}
	
} 
  1. A rabbit hides in one of the 10 circular holes. The wolf does not find the rabbit in the first hole.
    If you go to the third hole and you can't find it, you go to the sixth hole and you go to the second hole, and then you go to the sixth hole, and then you go to the third hole and find another hole at a time.
    Go find the rabbit... In this way, the result has not been found rabbits, excuse me: rabbits may hide in which hole?
#include "stdio.h"
typedef struct{
	int id;
	int flag;
}st;

void main(){
	int i;
	st a[11];
	for(i=1;i<=10;i++){
		a[i].id=i;
		a[i].flag=0;
	}
	i=1;
	int sum=0;
	while(i<10){
		if((sum+i)%10==0)	sum=10;
		else sum=(sum+i)%10;
		a[sum].flag=1;
//		printf("%d\n",a[sum].id);
		i++;
	}
	for(i=1;i<=10;i++){
		if(a[i].flag==0)	printf("%d\n",a[i].id);
	}
}

Posted by gplaurin on Mon, 01 Apr 2019 14:24:28 -0700