m0_73394375 2022-09-16 21:25 采纳率: 100%
浏览 68
已结题

python和C语言的互转

Python转C语言

para = "Letting go of a negative habit happens by making one positive choice at a time. " \
       "Creating a desired achievement comes about in the same way."

para = para.split()
arr = []
num_a = 0
word_num = 0
word_line = 0
count_line = 0
max_line = 72

for p in para:
    if p == 'a':
        p = "//"+p+"//"
        num_a += 1
    word_num += 1
    word_line = len(p)
    count_line += word_line
    arr.append(p)

arr = ' '.join(arr)
print(arr)

输出是

Letting go of //a// negative habit happens by making one positive choice at //a// time. Creating //a// desired achievement comes about in the same way.

  • 写回答

3条回答 默认 最新

  • fuill 2022-09-16 23:21
    关注

    判断句子中的a即可

    img

    #include <stdio.h>
    #include <string.h>
    int main()
    {
        char t[]={"Letting go of a negative habit happens by making one positive choice at a time. " 
           "Creating a desired achievement comes about in the same way."};
        int len=strlen(t);
        for(int i=0;i<len;i++)
        {
            if(t[i]=='a'&&i-1>0&&i+1<len-1)
            {
                if(t[i-1]==' '&&t[i+1]==' ')
                {
                    printf("//%c//",t[i]);
                }
                else
                {
                    printf("%c",t[i]);
                }
            }
            else
            {
                printf("%c",t[i]);
            }
        }
        printf("\n");
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月25日
  • 已采纳回答 9月17日
  • 创建了问题 9月16日