Question Set for Re-examination

Keywords: REST

  1. The problem of monkeys eating peaches: On the first day, the monkeys picked several peaches and ate half of them immediately. They were not addicted to them. They ate one more peach.
    The next morning he ate half of the remaining peaches and one more.
    Every morning after that, I ate half and one of the rest of the previous day. When I wanted to eat again on the 10th morning, I saw that there was only one peach left. Seek how many you picked on the first day.
    Thinking backward
#include "stdio.h"

void main(){
	int sum=1,i;
	for(i=9;i>0;i--){
		sum=sum+1;
		sum=sum*2;
		printf("%d-->%d\n",i,sum);
	}
} 
  1. Two table tennis teams compete, each with three players. The first team is a, B and c, and the second team is x, y and Z. The competition list has been decided by lot.
    The players were asked about the list of matches. a says he's not compared with x, c says he's not compared with x,z. Please program to find out the list of the three teams.
#include "stdio.h"
void main(){
	char i,j,k;//i->x,j->y,k->z
	for(i='a';i<='c';i++){
		for(j='a';j<='c';j++){
			for(k='a';k<='c';k++){
				if(i!=j&&i!=k&&j!=k){
					if(i!='a'&&i!='c'&&k!='c')
					printf("x->%c,y->%c,z->%c\n",i,j,k);
				}
			}
		}
	}	
}
  1. A 5-digit number to determine whether it is palindrome. That is 12321 is palindrome number, the number of bits is the same as 10000 bits, and the number of ten bits is the same as 1000 bits.
#include "stdio.h"
void main(){
	int a[5];
	int data=12333421;
	int k=0,temp=data,i,flag=1;
	while(temp!=0){
		a[k++]=temp%10;
		temp=temp/10;
		printf("%d\n",a[k-1]);
	}
	for(i=0;i<k/2;i++){
		if(a[i]!=a[k-1-i]) flag=0;
	}
	if(flag)	printf("yes");
	else printf("no");
		
}
  1. There are two disk files A and B, each containing a line of letters. The information in these two files is required to be merged (arranged alphabetically) and output to a new file C.
#include "stdio.h"
#include "string.h"

void main() {
	FILE *in1,*in2,*out;
	if((in1=fopen("1.txt","r"))==0) {
		printf("error");
		return;
	}
	if((in2=fopen("2.txt","r"))==0) {
		printf("error");
		return;
	}
	if((out=fopen("3.txt","w"))==0) {
		printf("error");
		return;
	}
	char ch[100],c,temp;
	int k=0,i,j;
	while(!feof(in1)) {
		c=fgetc(in1);
		if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
			ch[k++]=c;
	}
	while(!feof(in2)) {
		c=fgetc(in2);
		if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
			ch[k++]=c;
	}
	for(i=0;i<strlen(ch);i++){
		k=i;
		for(j=i;j<strlen(ch);j++){
			if(ch[k]>ch[j]) k=j;
		}
		if(k!=i){
			temp=ch[i];
			ch[i]=ch[k];
			ch[k]=temp;
		}
	}
	for(i=0;i<strlen(ch);i++){
		fputc(ch[i],out);
		fputchar(ch[i]);
	}
	fclose(in1);
	fclose(in2);
	fclose(out);
}
  1. 809*?= 800*??+9*?? where??? Represents two digits, 809*?? is four digits, and the result of 8*?? is two digits.
    The result of 9*?? is three digits. Request?? Represents two digits, and 809*?? after the results.
#include "stdio.h"
void main(){
	int a;
	for(a=10;a<100;a++){
		if(8*a>=10&&8*a<100){
			if(9*a>=100&&9*a<1000){
				if(809*a==800*a+9*a)
				printf("%d,%d",a,809*a);
			}
		}		
	} 
}

Posted by mrMarcus on Sun, 31 Mar 2019 19:57:28 -0700