77kki 2021-05-08 08:27 采纳率: 60%
浏览 32
已采纳

求大佬[face]emoji:054.png[/face]在努力敲代码中,但是是新手很多语句都不规范

求大佬[face]emoji:054.png[/face]在努力敲代码中,但是是新手很多语句都不规范,思路也不是很清晰[face]emoji:002.png[/face]
  • 写回答

2条回答 默认 最新

  • benbenli 2021-05-08 09:28
    关注

    用C语言写了。

    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
        int n, l;
        char s[101];
        char *p, *m, *q;
    
        printf("Please enter the length N: \n");
        scanf("%d", &n);
        
        if (n <= 0)
        {
            printf("Length must be positive.\n");
            return -1;
        }
        else if (n %2 == 1)
        {
            printf("Length must be even number.\n");
            return -1;
        }
        
        printf("Please enter the string S (max 100 characters): ");
        scanf("%s", s);
    
        l = strlen(s);
        if (l != n)
        {
            printf("String length %d is not equal to %d\n", l, n);
            return -1;
        }
        
        p = s;
        m = s + n / 2;
        q = m;
        while (p < m)
        {
            if (*p++ != *q++)
            {
                printf("No\n");
                return 0;
            }
        }
        printf("Yes\n");
        return 0;
    }
    
    // Output
    Please enter the length N:                                                                                                                                                         
    6                                                                                                                                                                                  
    Please enter the string S (max 100 characters): abcabc                                                                                                                             
    Yes
    
    
    Please enter the length N:                                                                                                                                                         
    6                                                                                                                                                                                  
    Please enter the string S (max 100 characters): abcabd                                                                                                                             
    No 

    附注:求赞助积分和C币。加入CSDN将近20年了。最近几年忙小孩没登录。刚才搜索到一本电子书想下载,需要20积分/C币。已经收到8元了,还差12元。赞助多少都可以。多谢。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程