Operational requirements 20190905-3 command line and console programming

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

 

1. familiar with the command line and console

And the application is assumed that there a.exe b.txt file in the current directory, please auxiliary data flow graph and text description to the following effect what console commands Yes.

A: B which a program content as the input data, the final result and save the result is output to 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.

code show as below:

 

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c;
    scanf("a=%d b=%d c=%d",&a,&b,&c);
    printf("%d\n",a);
    printf("%d\n",b);
    printf("%d\n",c);
    return 0;
}

Operating results are as follows:

 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.

Screenshot below:

(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

重难点:这个题目属于比较简单的题目,就是判定一下数据是奇数还是偶数,判定后分别给予不同的处理罢了。

代码片段:

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

执行效果截图:

1002 写出这个数

重难点:我感觉这个题的重难点是如何把一个数各分位上的数加起来,我采用了将一个数按字符串输入,然后再转换成数字,用For循环将所有的数加起来,将0到9用拼音表示存在数组中,通过除法和除余来判断各个位上的数字然后再分别输出。

代码片段:

#include<stdio.h>
int main(){
    char n[100];
    int i=0;
    int j;
    scanf("%s",&n);
    for(;n[i]!='\0';i++)
    {
        j=j+(n[i]-'0');
    }
    char a[10][10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
    if(j>99)
    {
        printf("%s ",a[j/100]);
        printf("%s ",a[j%100/10]);
        printf("%s",a[j%100%10]);
    }
    else if(j>9)
    {
        printf("%s ",a[j/10]);
        printf("%s",a[j%10]);
    }
    else{
        printf("%s",a[j]);
    }
    return 0;
}

执行效果截图:

1003 我要通过

重难点:我认为这道题还是比较难的,首先这个读题就花费了很多的时间,第三个条件是最难判断的,前期一直不对,后来看了他给的测试用例,才猜测P前面A的个数乘以P和T之间的A的个数必须等于T后面的A的个数。

代码片段:

def func(lis):

    if 'A' in lis and 'P' in lis and 'T' in lis:

        if len(set(lis)) == 3 and lis.index('P') < lis.index('T'):
            start = lis.index('P')
            end = lis.index('T')
            numbefore = len(lis[:start])
            nummid = len(lis[start+1:end])
            numafter = len(lis[end+1:])

            if numbefore*nummid == numafter:
                return 1
            else:
                return 0
        return 0
    return 0


n = int(input())
ret = []
for i in range(n):
    ret.append(list(input()))
for lis in ret:
    if func(lis):
        print('YES')
    else:
        print('NO')

执行结果截图:

 

(4) PSP

 

在同一篇博客中,参照教材第35页表2-2和表2-3,为上述3个题目制作PSP阶段表格。

PSP阶段表格第1列分类,如功能1、功能2、测试功能1等。

总结出现时间差的原因

1 C语言的基本语法忘掉的太多,很多时候出现很低级的错误。

2 编写代码是逻辑混乱,对如何使用数组竟然产生了疑问,编写了一半又去查找关于数组方面的资料,导致编码时间过长。

3 对题目的解读能力太差,一直没有读懂第三个条件该如何写,测试了很多用例不通过,后来在给定的用例中发现规律,三个位置的A的数量是存在关系的,通过这种关系写的限制条件,这个题目我是用Python写的,因为我感觉用C语言实在是太麻烦了。

 

Guess you like

Origin www.cnblogs.com/hejw031/p/11493807.html