Xu Shanshan 20190905-3 command line and console programming

This job requires see [https://edu.cnblogs.com/campus/nenu/2019fall/homework/5523]

1. familiar with the command line and console 

(1) assuming the presence of applications and files a.exe b.txt in the current directory, and the auxiliary data stream in FIG what role the following text console commands Yes. (5 points)

 a.exe < b.txt > c.txt

 

  A: The role of this console command in the content file b.txt, flowing-a.exe were, and finally to C.txt, that is, the basic flow of data from a to b by C, a data flow diagram as FIG. Fig.

(2) Use the C statement develop applications d.exe, read commands from the console command line parameters, respectively, and print out the value of a, b, c in the console. Run the following example the effect of the form (6 points)

d.exe a = 1 b = 2 c = 3

1

2

3

 

d.exe a = b = 22 c = 11 33

11

22

33

A: Code and results are as follows:

#include<stdio.h>
int main(){
    int a,b,c;
    while(scanf("a=%d b=%d c=%d",&a,&b,&c)){
        printf("%d\n%d\n%d",a,b,c);
    } 
}

 

2. familiar with the test case

(2) in the title set PAT (Basic Level) Practice (Chinese) 3 optionally in the complete title. Shots are as follows, in claim 1 comprising a red check mark, 2. Reference numeral 3 user name (in this example Young). (30 points)

Note that you need to read this whole topic can begin to do the job title, there are requirements for time recording and interpretation of the code.

A: Title completion as shown:

(3) Code Interpretation. (20 points)

Published blog, introduced the three topics highlighted in the code / difficulty, code snippet shows important, given the effect of the implementation of screenshots to show you feel proud, breakthrough, difficult places.

answer:

①1001 killed attractiveness of the (3n + 1) guess

#include<stdio.h>
int main(){
	int n,count=0;
	scanf("%d",&n);
	while(n!=1){
		if(n%2==0){
			n=n/2;
		}else{
			n=(3*n+1)/2;
		}
		count++;
	}
	printf("%d\n",count);
}

Another output format integer ②1006

  

#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    while(n/100!=0){
        printf("B");
        n=n-100;
    }
    while(n/10!=0){
        printf("S");
        n=n-10;
    }
    int a=1;
    while(n!=0){
        printf("%d",a++);
        n=n-1;
    }
}

 

③1007 of prime conjecture

#include<stdio.h>
#include<math.h>

int isPrime_1(int num){
    int tmp=sqrt(num);
    for(int i=2;i<=tmp;i++){
        if(num%i==0)
        return 0;
    }
    return 1;
}

int main(){
    int N;
    int count=0;
    int left=2;
    scanf("%d",&N);
    if(N>3){
        for(int i=3;i<=N;i++){
            if(isPrime_1(i)){
                if(i-left==2){
                    count++;
                }
                left=i;
            }
        }
    }
    printf("%d\n",count);
}

(4) PSP

The reason of the time difference appears:

1. c long time without language, it is not familiar with the c language, some forgotten knowledge.

2. Select the topic, some hard, some easy.

 

Guess you like

Origin www.cnblogs.com/samndbk/p/11496999.html