Luo Yang Meihui 20190905-3 command line and console programming

Requirements for this job see https://edu.cnblogs.com/campus/nenu/2019fall/homework/5523

1. familiar with the command line and console

And the application is assumed that there a.exe b.txt file in the current directory, and the auxiliary data stream in FIG what role the following text console commands Yes.

a.exe < b.txt > c.txt

Data flow diagram:

B is the content of the text data a program input, the result obtained after a program is running and then output to the text c.

 

Please made to develop applications in C d.exe, read commands from the console command line parameters, respectively, and print out the value of a, b, c in the console. Operating results shaped like the following example.

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

1

2

3

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

11

22

33

 code show as below:

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

Screenshot implementation of the results:

 2. familiar with the test case

(1) Make the site [https://pintia.cn/] registered account.     

(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. Username.

 

(3) Code Interpretation. 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.

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

重点:首先判断n是奇数还是偶数,每次循环累加一次,循环终止条件是n=1.

重要代码片段:

int main(){
    int n;
    scanf("%d",&n);
    int s=0;
    while(n!=1){
        if(n%2==0){
            n=n/2;
            s++;
        }
        else{
            n=(3*n+1)/2;
            s++;
        }
    }
    printf("%d",s);
    return 0;
} 

执行效果截图:

 

1006 换个格式输出整数 

重点:输入一个三位数,计算出个位十位和百位数字,循环输出个数.

重要代码片段:

int main(){
    int n,B,S,G;
    scanf("%d",&n);
    B=n/100;
    S=n%100/10;
    G=n%10;
    for(int i=0;i<B;i++)  
        printf("B");
    for(int i=0;i<S;i++)  
        printf("S");
    for(int i=1;i<=G;i++) 
        printf("%d",i);
    return 0;
}

执行效果截图:

 

1011 A+B 和 C 

重点:输入测试次数,判断a+b是否大于c,循环多次输出结果.

重要代码片段:

int main()
{
    int num,i;
    scanf("%d",&num);
    long a,b,c;
    for(i=0;i<num;i++){
        scanf("%ld%ld%ld",&a,&b,&c);
        if(a+b>c)
            printf("Case #%d: true\n",i+1);
        else
            printf("Case #%d: false\n",i+1);
    }
    return 0;
}

执行效果截图:

 

(4) PSP

 

总结:本次作业选择的三道编程题难易程度其实不大,但对我来说还是比较困难,花费较长的时间来完成。很多编程题都是能够看懂代码但上手操作后就会出错,还是实际操作的次数太少,相信通过这门课以后也会有所改善,也是对自己的一种锻炼吧。

Guess you like

Origin www.cnblogs.com/lymh/p/11491355.html