【C初阶——基础刷题】刷题8

本文由@睡觉待开机原创,转载请注明出处。
本内容在csdn网站首发
欢迎各位点赞—评论—收藏
如果存在不足之处请评论留言,共同进步!

这里写目录标题

  • 题目链接
  • T1:
  • T2:
  • T3:
  • T4:
  • T5:
  • T6:
  • T7:
  • T8:
  • T9:
  • T10:

题目链接

  1. 平均平均⾝⾼00:00:00⸺00:06:05题号:(⽆)链接:https://www.nowcoder.com/questio
    nTerminal/487e757828ed4d40aa391b305105df68
  2. HTTP状态码00:06:05⸺00:13:38题号:BC69链接:https://www.nowcoder.com/practic
    e/99dba043761e43c2a6f931e2c5c247c7?tpId=290&tqId=39857&ru=/exam/oj
  3. 数字三⻆形00:13:38⸺00:18:15题号:BC113链接:https://www.nowcoder.com/practice/804a22929b844e6b9379a5e90b5e2197?
  4. 公务员⾯试00:18:15⸺00:26:15题号:BC93链接:https://www.nowcoder.com/practic
    e/f3a134908d5b41869f14f58307008a97?tpId=290&tqId=39881&ru=/exam/oj
  5. 有序序列插⼊⼀个数00:26:15⸺00:43:25题号:BC123链接:https://www.nowcoder.co
    m/practice/444e87f938464906a1649cff236b102b?tpId=290&tqId=39911&ru=/exam/oj
  6. 筛选法求素数00:43:25⸺01:07:19题号:BC127链接:https://www.nowcoder.com/pra
    ctice/06c3dcc303654ef4926654023eca1e5a?tpId=290&tqId=39915&ru=/exam/oj
  7. 图像相似度01:07:19⸺01:14:20题号:BC135链接:https://www.nowcoder.com/practic
    e/f2952ee3bb5c48a9be6c261e29dd1092?tpId=290&tqId=39923&ru=/exam/oj
  8. 登录验证01:14:20⸺01:21:50题号:BC144链接:https://www.nowcoder.com/practic
    e/799daf76369c4fb1a2e2d56f885225ae?tpId=290&tqId=39932&ru=/exam/oj
  9. 包含数字9的数01:21:50⸺01:27:20题号:BC89链接:https://www.nowcoder.com/pra
    ctice/0948f4f3344c452f843afd3585dd0f8d?tpId=290&tqId=39877&ru=/exam/oj
  10. 奇偶统计01:27:20⸺01:34:39题号:BC80链接:https://www.nowcoder.com/practic
    e/04de8eb0ecab426fa6be3ae99af17210?tpId=290&tqId=39868&ru=/exam/oj

T1:

【C初阶——基础刷题】刷题8_第1张图片
解:

#include 

int main() {
    double arr[5] = {0};
    int i = 0;
    double sum = 0;
    for(i = 0;i<5;i++)
    {
        scanf("%lf",&arr[i]);
        sum+=arr[i];
    }
    printf("%.2lf\n",sum/5.0);
    return 0;
}

一般可能会搞个数组存一下数据然后进行处理,其实这个数据没必要存储,节约内存空间,提升效率,可以修改一下代码:

#include 

int main() {
    int i = 0;
    double sum = 0;
    double m = 0.0;
    for(i = 0;i<5;i++)
    {
        scanf("%lf",&m);
        sum+=m;
    }
    printf("%.2lf\n",sum/5.0);
    return 0;
}

T2:

【C初阶——基础刷题】刷题8_第2张图片
解:

#include 

int main() 
{
    int n;
    while (scanf("%d", &n) != EOF)
     {
        switch(n)
        {
            case 200:
            printf("OK\n");
            break;
            case 202:
            printf("Accepted\n");
            break;
            case 400:
            printf("Bad Request\n");
            break;
            case 403:
            printf("Forbidden\n");
            break;
            case 404:
            printf("Not Found\n");
            break;
            case 500:
            printf("Internal Server Error\n");
            break;
            case 502:
            printf("Bad Gateway\n");
            break;
        }
    }
    return 0;
}

T3:

【C初阶——基础刷题】刷题8_第3张图片
解:

#include 

int main()
 {
    int n = 0;
    while(~scanf("%d",&n))
    {
        int i = 0;
        int j = 0;
        for(i=0;i<n;i++)
        {
            for(j=1;j<=i+1;j++)
            {
                printf("%d ",j);
            }
            printf("\n");
        }
    }
    return 0;
}

T4:

#include 

int main() {
     int arr[7] = {0};
    while (scanf("%d %d %d %d %d %d %d", &arr[0], &arr[1], &arr[2], &arr[3],
                 &arr[4], &arr[5], &arr[6]) != EOF) {
                   
    int i = 0;
    int max = 0;
    int min = 100;
    double sum = 0.0;
        for (i = 0; i < 7; i++) {

            if (arr[i] > max)
                max = arr[i];
            if (arr[i] < min)
                min = arr[i];
            sum += arr[i];

        }
        sum -= (max + min);
        printf("%.2lf\n", sum / 5.0);
    }

    return 0;
}

T5:

【C初阶——基础刷题】刷题8_第4张图片
解:

#include 

int main()
{
   int arr[51] = {0};
   int i = 0;
   int n = 0;
   while(scanf("%d",&n)!=EOF)
   {
    //输入数据
        for(i = 0;i<n;i++)
        {
            scanf("%d",&arr[i]);
        }
    //插入数据
    int q = 0;
    scanf("%d",&q);
    for(i = 0;i<n;i++)
    {
        if(q<arr[i])
        {
            int j = 0;
            //往后挪动一位
            for(j=n;j> i;j--)
            {
                arr[j] = arr[j-1];
            }
            arr[i] = q;
            break;
        }
        else
        {
            ;
        }
    }
    //特殊情况
    if(i==n)
    {
         arr[i] = q;
    }
    
    for(i = 0;i<n+1;i++)
    {
        printf("%d ",arr[i]);
    }
   }
   
    return 0;
}

T6:

【C初阶——基础刷题】刷题8_第5张图片
0%任何非0数字=0!
//一般这个筛选法比较麻烦

#include 
int main() 
{
    int n = 0;
    int arr[101] = {0};
    int count = 0;
    while(~scanf("%d",&n))
    {
        //存入数据
        int i = 0;
        for(i = 2;i<=n;i++)
        {
            arr[i] = i;
        }
        //生成除数,顺便置换为0
        int j = 0;
        for(j = 2;j< n;j++)
        {
           for(i = j+1;i<= n;i++)
           {
            if(arr[i]&&arr[i]%j==0)
            {
                arr[i] = 0;
                count++;
            }
           }
        }

    for(i = 0;i<=n;i++)
    {
        if(arr[i])
        {
            printf("%d ",arr[i]);
        }
    }
    printf("\n%d",count);
    }
    return 0;
}

//试除法比较简单:
【C初阶——基础刷题】刷题8_第6张图片

T7:

【C初阶——基础刷题】刷题8_第7张图片

#include 

int main() {
    
    int m = 0;
    int n = 0;
    while(scanf("%d %d",&m,&n)!=EOF)
    {
        int count = 0;
        int arr1[m][n];
        int arr2[m][n];
        int i = 0;
        int j = 0;
        for(i = 0;i<m;i++)
        {
            for(j = 0;j<n;j++)
            {
                scanf("%d",&arr1[i][j]);
            }
        }
        for(i = 0;i<m;i++)
        {
            for(j = 0;j<n;j++)
            {
                scanf("%d",&arr2[i][j]);
            }
        }

        for(i = 0;i<m;i++)
        {
            for(j = 0;j<n;j++)
            {
                if(arr1[i][j]==arr2[i][j])
                {
                    count++;
                }
            }
        }
        printf("%.2lf",100.0*count/(m*n));
    }
    return 0;
}

T8:

【C初阶——基础刷题】刷题8_第8张图片
解:

#include 
#include

int main() 
{
    char a[100] = {0};
    char b[100] = {0};
    while (scanf("%s %s", &a[0], &b[0]) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to
        if(!strcmp(a,"admin")&&!strcmp(b,"admin"))
        {
            printf("Login Success!\n");
        } 
        else {
        {
            printf("Login Fail!\n");
        }
        }
    }
    return 0;
}

T9:

【C初阶——基础刷题】刷题8_第9张图片
解:

#include 

int main() 
{
    int count = 0;
   int i = 0;
   for(i = 1;i<=2019;i++)
   {
    int t = i;
    while(t)
    {
        if(t%10==9)
        {
            count++;
            break;
        }
        else
        {
        t/=10;
        }
    }
   }
   printf("%d",count);
    return 0;
}

T10:

【C初阶——基础刷题】刷题8_第10张图片

#include 

int main() {
    int n = 0;
    int i = 0;
    scanf("%d",&n);
    int odd= 0;
    for(i = 0;i<=n;i++)
    {
        if(i%2)
        {
            odd++;
        }
    }
    printf("%d %d",odd,n-odd);
    return 0;
}

改进:

#include 

int main() {
    int n = 0;
    int i = 0;
    scanf("%d",&n);
    int odd= 0;
    if(n%2)
    {
        odd = n/2+1;
    }
    else {
    odd=n/2;
    }
    printf("%d %d",odd,n-odd);
    return 0;
}

你可能感兴趣的:(C语言初阶基础刷题,c语言,开发语言)